Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugzilla 1507822 - Update plan info on service instance update #2409

Merged
merged 1 commit into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions app/scripts/controllers/serviceInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ angular.module('openshiftConsole')
var watches = [];
var secretWatchers = [];
var serviceClassPromise;
var servicePlansPromise;

var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');
var serviceInstanceReady = $filter('isServiceInstanceReady');
Expand Down Expand Up @@ -128,33 +129,50 @@ angular.module('openshiftConsole')
updateParameterData();
};

var updateServiceClass = function() {
// If we've previously loaded the service class or a request is in flight, don't do anything.
if (!$scope.serviceInstance || $scope.serviceClass || serviceClassPromise) {
var updateServicePlan = function() {
var servicePlanName = _.get($scope.serviceInstance, 'spec.clusterServicePlanRef.name');
$scope.plan = _.find($scope.servicePlans, { metadata: { name: servicePlanName } });
updateParameterSchema();
updateEditable();
};

var updateServicePlans = function() {
if (!$scope.serviceClass || servicePlansPromise) {
return;
}

serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function (serviceClass) {
$scope.serviceClass = serviceClass;
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, $scope.serviceClass);

updateBreadcrumbs();
serviceClassPromise = null;

Catalog.getServicePlansForServiceClass($scope.serviceClass).then(function (plans) {
plans = plans.by('metadata.name');

if (!$scope.servicePlans) {
servicePlansPromise = Catalog.getServicePlansForServiceClass($scope.serviceClass).then(function (plans) {
var servicePlanName = _.get($scope.serviceInstance, 'spec.clusterServicePlanRef.name');
$scope.servicePlans = _.reject(plans, function(plan) {
$scope.servicePlans = _.reject(plans.by('metadata.name'), function(plan) {
return _.get(plan, 'status.removedFromBrokerCatalog') && (plan.metadata.name !== servicePlanName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized if you change the instance plan twice without leaving the page, you'll probably be able to select a removed plan again if it was initially selected. Nothing related to this PR, but we might want to test and open an issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought of the same thing but really really really edge case. Can't think of a good fix except to re-request the plans on a change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if current instance plan != $scope.plan on instance watch updates and re-filter the existing $scope.servicePlans list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I was actually thinking of plans that were removed after the original fetch.

});

$scope.plan = plans[servicePlanName];
updateServicePlan();
servicePlansPromise = null;
});
} else {
updateServicePlan();
}
};

var updateServiceClass = function() {
if (!$scope.serviceInstance || serviceClassPromise) {
return;
}

if ($scope.serviceClass) {
updateServicePlans();
} else {
serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function (serviceClass) {
$scope.serviceClass = serviceClass;
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, $scope.serviceClass);

updateParameterSchema();
updateEditable();
updateBreadcrumbs();
serviceClassPromise = null;
updateServicePlans();
});
});
}
};

var serviceResolved = function(serviceInstance, action) {
Expand Down
46 changes: 27 additions & 19 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6356,15 +6356,15 @@ e.showParameterValues = !e.showParameterValues;
}, e.closeEditDialog = function() {
e.editDialogShown = !1;
};
var m, p = [], f = [], g = t("serviceInstanceDisplayName"), v = t("isServiceInstanceReady"), h = a.getPreferredVersion("servicebindings");
var m, p, f = [], g = [], v = t("serviceInstanceDisplayName"), h = t("isServiceInstanceReady"), y = a.getPreferredVersion("servicebindings");
e.serviceInstancesVersion = a.getPreferredVersion("serviceinstances");
var y = function() {
var b = function() {
e.breadcrumbs.push({
title: e.displayName
});
}, b = function() {
}, C = function() {
if (e.serviceInstance && e.parameterSchema) {
s.unwatchAll(f), f = [], e.allowParametersReveal = o.canI("secrets", "get", e.projectName), e.parameterData = {}, e.opaqueParameterKeys = [];
s.unwatchAll(g), g = [], e.allowParametersReveal = o.canI("secrets", "get", e.projectName), e.parameterData = {}, e.opaqueParameterKeys = [];
var t = e.allowParametersReveal ? "" : "*****";
_.each(_.keys(_.get(e.parameterSchema, "properties")), function(n) {
e.parameterData[n] = t;
Expand All @@ -6373,7 +6373,7 @@ var n = _.get(e.serviceInstance, "status.externalProperties.parameters", {});
_.each(_.keys(n), function(t) {
"<redacted>" === n[t] ? e.parameterData[t] = "*****" : (e.parameterData[t] = n[t], e.opaqueParameterKeys.push(t));
}), e.allowParametersReveal && _.each(_.get(e.serviceInstance, "spec.parametersFrom"), function(t) {
f.push(s.watchObject("secrets", _.get(t, "secretKeyRef.name"), e.projectContext, function(n) {
g.push(s.watchObject("secrets", _.get(t, "secretKeyRef.name"), e.projectContext, function(n) {
try {
var a = JSON.parse(u.decodeSecretData(n.data)[t.secretKeyRef.key]);
_.extend(e.parameterData, a);
Expand All @@ -6383,34 +6383,42 @@ c.warn("Unable to load parameters from secret " + _.get(t, "secretKeyRef.name"),
}));
});
}
}, C = function() {
}, S = function() {
if (e.plan && e.serviceClass && e.serviceInstance) {
var t = _.get(e.plan, "spec.instanceUpdateParameterSchema"), n = _.size(_.get(t, "properties")) > 0 || _.get(e.serviceClass, "spec.planUpdatable") && _.size(e.servicePlans) > 1;
e.editAvailable = n && v(e.serviceInstance) && !_.get(e.serviceInstance, "metadata.deletionTimestamp");
e.editAvailable = n && h(e.serviceInstance) && !_.get(e.serviceInstance, "metadata.deletionTimestamp");
}
}, S = function() {
e.parameterFormDefinition = angular.copy(_.get(e.plan, "spec.externalMetadata.schemas.service_instance.update.openshift_form_definition")), e.parameterSchema = _.get(e.plan, "spec.instanceCreateParameterSchema"), b();
}, w = function() {
!e.serviceInstance || e.serviceClass || m || (m = d.fetchServiceClassForInstance(e.serviceInstance).then(function(t) {
e.serviceClass = t, e.displayName = g(e.serviceInstance, e.serviceClass), y(), m = null, i.getServicePlansForServiceClass(e.serviceClass).then(function(t) {
t = t.by("metadata.name");
e.parameterFormDefinition = angular.copy(_.get(e.plan, "spec.externalMetadata.schemas.service_instance.update.openshift_form_definition")), e.parameterSchema = _.get(e.plan, "spec.instanceCreateParameterSchema"), C();
}, k = function() {
var t = _.get(e.serviceInstance, "spec.clusterServicePlanRef.name");
e.plan = _.find(e.servicePlans, {
metadata: {
name: t
}
}), w(), S();
}, P = function() {
e.serviceClass && !p && (e.servicePlans ? k() : p = i.getServicePlansForServiceClass(e.serviceClass).then(function(t) {
var n = _.get(e.serviceInstance, "spec.clusterServicePlanRef.name");
e.servicePlans = _.reject(t, function(e) {
e.servicePlans = _.reject(t.by("metadata.name"), function(e) {
return _.get(e, "status.removedFromBrokerCatalog") && e.metadata.name !== n;
}), e.plan = t[n], S(), C();
});
}), k(), p = null;
}));
}, j = function() {
e.serviceInstance && !m && (e.serviceClass ? P() : m = d.fetchServiceClassForInstance(e.serviceInstance).then(function(t) {
e.serviceClass = t, e.displayName = v(e.serviceInstance, e.serviceClass), b(), m = null, P();
}));
}, k = function(t, n) {
}, R = function(t, n) {
e.loaded = !0, e.serviceInstance = t, "DELETED" === n && (e.alerts.deleted = {
type: "warning",
message: "This provisioned service has been deleted."
}), w(), b(), C();
}), j(), C(), S();
};
l.get(n.project).then(_.spread(function(a, o) {
e.project = a, e.projectContext = o, s.get(e.serviceInstancesVersion, n.instance, o, {
errorNotification: !1
}).then(function(t) {
k(t), p.push(s.watchObject(e.serviceInstancesVersion, n.instance, o, k)), p.push(s.watch(h, o, function(n) {
R(t), f.push(s.watchObject(e.serviceInstancesVersion, n.instance, o, R)), f.push(s.watch(y, o, function(n) {
var a = n.by("metadata.name");
e.bindings = r.getBindingsForResource(a, t);
}));
Expand All @@ -6428,7 +6436,7 @@ message: "The service details could not be loaded.",
details: t("getErrorDetails")(n)
};
})), e.$on("$destroy", function() {
s.unwatchAll(p), s.unwatchAll(f);
s.unwatchAll(f), s.unwatchAll(g);
});
} ]), angular.module("openshiftConsole").controller("SecretsController", [ "$routeParams", "$scope", "DataService", "ProjectsService", function(e, t, n, a) {
t.projectName = e.project, t.secretsByType = {}, a.get(e.project).then(_.spread(function(e, a) {
Expand Down