From 2ca25ec2b7511d2418432a04772a82137006cfbe Mon Sep 17 00:00:00 2001 From: velandy Date: Wed, 24 May 2017 18:27:37 -0400 Subject: [PATCH] Bug 278 - Allow updating of NSD when there are instantiated network services Signed-off-by: velandy --- skyquake/plugins/composer/api/composer.js | 8 +- .../src/src/components/CatalogItems.js | 4 +- .../EditDescriptorModelProperties.js | 2 +- .../src/src/stores/CatalogDataStore.js | 75 +++++-------------- skyquake/plugins/launchpad/api/launchpad.js | 6 +- 5 files changed, 24 insertions(+), 71 deletions(-) diff --git a/skyquake/plugins/composer/api/composer.js b/skyquake/plugins/composer/api/composer.js index e9e4be1da..93cc55351 100644 --- a/skyquake/plugins/composer/api/composer.js +++ b/skyquake/plugins/composer/api/composer.js @@ -125,8 +125,7 @@ Composer.get = function(req) { response[0].descriptors = JSON.parse(result[0].body).collection['nsd:nsd']; if (result[2].body) { var data = JSON.parse(result[2].body); - if (data && data["nsr:ns-instance-opdata"] && data["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"]) { - var nsdRefCountCollection = data["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"]; + if (data && data["nsr:ns-instance-opdata"]) { response[0].descriptors.map(function(nsd) { if (!nsd["meta"]) { nsd["meta"] = {}; @@ -134,9 +133,6 @@ Composer.get = function(req) { if (typeof nsd['meta'] == 'string') { nsd['meta'] = JSON.parse(nsd['meta']); } - nsd["meta"]["instance-ref-count"] = _.findWhere(nsdRefCountCollection, { - "nsd-id-ref": nsd.id - })["instance-ref-count"]; }); } } @@ -487,7 +483,7 @@ PackageManager.copy = function(req) { } /** - * This methods retrieves the status of package operations. It takes an optional + * This methods retrieves the status of package operations. It takes an optional * transaction id (id) this if present will return only that status otherwise * an array of status' will be response. */ diff --git a/skyquake/plugins/composer/src/src/components/CatalogItems.js b/skyquake/plugins/composer/src/src/components/CatalogItems.js index 78a18e04c..9b96bb5b0 100644 --- a/skyquake/plugins/composer/src/src/components/CatalogItems.js +++ b/skyquake/plugins/composer/src/src/components/CatalogItems.js @@ -88,8 +88,6 @@ const CatalogItems = React.createClass({ const isOpenForEdit = d.uiState.isOpenForEdit; const spanClassNames = ClassNames({'-is-selected': isSelected, '-is-open-for-edit': isOpenForEdit}); const sectionClassNames = ClassNames('catalog-item', {'-is-modified': isModified, '-is-deleted': isDeleted}); - const instanceCount = d.uiState['instance-ref-count']; - const instanceCountLabel = isNSD && instanceCount ? ({instanceCount}) : null; let type; if(isNSD) { type = 'nsd'; @@ -104,7 +102,7 @@ const CatalogItems = React.createClass({ {isModified ?
: null}
{type}
-
{d.name} {instanceCountLabel}
+
{d.name}
diff --git a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js index ad2bf3dc9..651c40d7b 100644 --- a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js +++ b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js @@ -324,7 +324,7 @@ export default function EditDescriptorModelProperties(props) { // We stick in a string when the user actually sets it to simplify things // but the correct thing happens when we serialize to user data let isEmptyLeafPresent = (value === EMPTY_LEAF_PRESENT || value === null); - let present = isEmptyLeafPresent ? EMPTY_LEAF_PRESENT : ""; + let present = isEmptyLeafPresent ? EMPTY_LEAF_PRESENT : [null]; const options = [ , diff --git a/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js b/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js index 06d134276..9179f2147 100644 --- a/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js +++ b/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js @@ -57,7 +57,6 @@ function createItem (type) { UID.assignUniqueId(newItem.uiState); newItem.uiState.isNew = true; newItem.uiState.modified = true; - newItem.uiState['instance-ref-count'] = 0; } return newItem; } @@ -189,7 +188,6 @@ class CatalogDataStore { }); updatedCatalogs.filter(d => d.type === 'nsd').forEach(catalog => { catalog.descriptors = catalog.descriptors.map(descriptor => { - const instanceRefCount = parseInt(descriptor.uiState['instance-ref-count'], 10); if (descriptor['constituent-vnfd']) { descriptor.vnfd = descriptor['constituent-vnfd'].map(d => { const vnfdId = d['vnfd-id-ref']; @@ -197,10 +195,6 @@ class CatalogDataStore { if (!vnfd) { throw new ReferenceError('no VNFD found in the VNFD Catalog for the constituent-vnfd: ' + d); } - if (!isNaN(instanceRefCount) && instanceRefCount > 0) { - // this will notify user that this item cannot be updated when/if they make a change to it - vnfd.uiState['instance-ref-count'] = instanceRefCount; - } // create an instance of this vnfd to carry transient ui state properties const instance = _cloneDeep(vnfd); instance.uiState['member-vnf-index'] = d['member-vnf-index']; @@ -319,17 +313,9 @@ class CatalogDataStore { // compare just the catalog uiState data (id, name, short-name, description, etc.) const modified = !areCatalogItemsMetaDataEqual(d, item); if (modified) { - if (d.uiState['instance-ref-count'] > 0) { - console.log('cannot edit NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot edit NSD/VNFD with references to instantiated Network Services' - }); - return _cloneDeep(d); - } else { - item.uiState.modified = modified; - requiresSave = true; - this.addSnapshot(item); - } + item.uiState.modified = modified; + requiresSave = true; + this.addSnapshot(item); } return item; } @@ -353,17 +339,9 @@ class CatalogDataStore { // replace the old descriptor with the updated one catalog.descriptors = catalog.descriptors.map(d => { if (d.id === descriptorId) { - if (d.uiState['instance-ref-count'] > 0) { - console.log('cannot edit NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot edit NSD/VNFD with references to instantiated Network Services' - }); - return _cloneDeep(d); - } else { - itemDescriptor.model.uiState.modified = true; - this.addSnapshot(itemDescriptor.model); - return itemDescriptor.model; - } + itemDescriptor.model.uiState.modified = true; + this.addSnapshot(itemDescriptor.model); + return itemDescriptor.model; } return d; }); @@ -415,27 +393,19 @@ class CatalogDataStore { if (item.uiState.isNew) { CatalogDataStore.confirmDelete(remove, confirmDeleteCancel); } else { - if (item.uiState['instance-ref-count'] > 0) { - console.log('cannot delete NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot delete NSD/VNFD with references to instantiated Network Services' - }); - undo(); - } else { - const confirmDeleteOK = event => { - event.preventDefault(); - item.uiState.deleted = true; - this.setState({catalogs: this.getCatalogs()}); - ModalOverlayActions.showModalOverlay.defer(); - this.getInstance().deleteCatalogItem(item.uiState.type, item.id) - .then(remove, undo) - .then(ModalOverlayActions.hideModalOverlay, ModalOverlayActions.hideModalOverlay) - .catch(function() { - console.log('overcoming ES6 unhandled rejection red herring'); - }); - }; - CatalogDataStore.confirmDelete(confirmDeleteOK, confirmDeleteCancel); - } + const confirmDeleteOK = event => { + event.preventDefault(); + item.uiState.deleted = true; + this.setState({catalogs: this.getCatalogs()}); + ModalOverlayActions.showModalOverlay.defer(); + this.getInstance().deleteCatalogItem(item.uiState.type, item.id) + .then(remove, undo) + .then(ModalOverlayActions.hideModalOverlay, ModalOverlayActions.hideModalOverlay) + .catch(function() { + console.log('overcoming ES6 unhandled rejection red herring'); + }); + }; + CatalogDataStore.confirmDelete(confirmDeleteOK, confirmDeleteCancel); } } } @@ -528,13 +498,6 @@ class CatalogDataStore { saveItem(item) { if (item) { - if (item.uiState['instance-ref-count'] > 0) { - console.log('cannot save NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot save NSD/VNFD with references to instantiated Network Services' - }); - return; - } const success = () => { delete item.uiState.modified; if (item.uiState.isNew) { diff --git a/skyquake/plugins/launchpad/api/launchpad.js b/skyquake/plugins/launchpad/api/launchpad.js index d74bb3e2e..4e288c3c0 100644 --- a/skyquake/plugins/launchpad/api/launchpad.js +++ b/skyquake/plugins/launchpad/api/launchpad.js @@ -266,8 +266,7 @@ Catalog.get = function(req) { response[0].descriptors = JSON.parse(result[0].body).collection['nsd:nsd']; if (result[2].body) { var data = JSON.parse(result[2].body); - if (data && data["nsr:ns-instance-opdata"] && data["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"]) { - var nsdRefCountCollection = data["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"]; + if (data && data["nsr:ns-instance-opdata"]) { response[0].descriptors.map(function(nsd) { if (!nsd["meta"]) { nsd["meta"] = {}; @@ -275,9 +274,6 @@ Catalog.get = function(req) { if (typeof nsd['meta'] == 'string') { nsd['meta'] = JSON.parse(nsd['meta']); } - nsd["meta"]["instance-ref-count"] = _.findWhere(nsdRefCountCollection, { - "nsd-id-ref": nsd.id - })["instance-ref-count"]; nsd["constituent-vnfd"] && nsd["constituent-vnfd"].map(function(v) { v.name = vnfdDict[v["vnfd-id-ref"]]; }) -- 2.17.1