summaryrefslogtreecommitdiffstats
path: root/catalog-ui
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2022-09-05 06:51:13 +0100
committerMichael Morris <michael.morris@est.tech>2022-09-15 08:56:26 +0000
commitab1295e98af672548c10411c245e7da465d9f239 (patch)
treec2ed6c870dcdd05dc2a5db971983f7f55956e89d /catalog-ui
parent4e9f61a3dce16a2d38e1db1437227377ae490a47 (diff)
Handle CSAR reading errors in Service Import
Issue-ID: SDC-4162 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Change-Id: I13c2d053991f4a2b12e4c845dcd0da6e1c00adae
Diffstat (limited to 'catalog-ui')
-rw-r--r--catalog-ui/src/app/utils/service-csar-reader.ts22
-rw-r--r--catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts45
-rw-r--r--catalog-ui/src/assets/languages/en_US.json4
3 files changed, 46 insertions, 25 deletions
diff --git a/catalog-ui/src/app/utils/service-csar-reader.ts b/catalog-ui/src/app/utils/service-csar-reader.ts
index 73b77559e2..90de53b8c9 100644
--- a/catalog-ui/src/app/utils/service-csar-reader.ts
+++ b/catalog-ui/src/app/utils/service-csar-reader.ts
@@ -26,17 +26,21 @@ export class ServiceCsarReader {
private serviceCsar = new ServiceCsar();
- public read(serviceCsarBlob:Blob): Promise<ServiceCsar> {
+ public read(serviceCsarBlob: Blob): Promise<ServiceCsar> {
const jsZip = require("jszip");
- return new Promise<ServiceCsar>((resolve) => {
+ return new Promise<ServiceCsar>((resolve, reject) => {
jsZip.loadAsync(serviceCsarBlob).then(async zip => {
- const toscaMetaFileContent = await zip.file("TOSCA-Metadata/TOSCA.meta").async("string");
- this.readToscaMeta(toscaMetaFileContent);
- const entryDefinitionFileContent = await zip.file(this.serviceCsar.entryDefinitionFileName).async("string");
- this.readServiceMetadata(entryDefinitionFileContent);
- const interfaceDefinitionFileContent = await zip.file(this.serviceCsar.interfaceDefinitionFileName).async("string");
- this.readServiceSubstitutionNode(interfaceDefinitionFileContent);
- resolve(this.serviceCsar);
+ try {
+ const toscaMetaFileContent = await zip.file("TOSCA-Metadata/TOSCA.meta").async("string");
+ this.readToscaMeta(toscaMetaFileContent);
+ const entryDefinitionFileContent = await zip.file(this.serviceCsar.entryDefinitionFileName).async("string");
+ this.readServiceMetadata(entryDefinitionFileContent);
+ const interfaceDefinitionFileContent = await zip.file(this.serviceCsar.interfaceDefinitionFileName).async("string");
+ this.readServiceSubstitutionNode(interfaceDefinitionFileContent);
+ resolve(this.serviceCsar);
+ } catch (error) {
+ reject(error);
+ }
});
});
}
diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
index 9d67b8eb69..77c93301b2 100644
--- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
+++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts
@@ -41,6 +41,7 @@ import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view
import {CATEGORY_SERVICE_METADATA_KEYS, PREVIOUS_CSAR_COMPONENT, DEFAULT_MODEL_NAME} from "../../../../utils/constants";
import {Observable} from "rxjs";
import {Model} from "../../../../models/model";
+import {SdcUiServices} from "onap-ui-angular/dist";
export class Validation {
componentNameValidationPattern:RegExp;
@@ -127,6 +128,7 @@ export class GeneralViewModel {
'sdcConfig',
'$state',
'ModalsHandler',
+ 'ModalServiceSdcUI',
'EventListenerService',
'Notification',
'Sdc.Services.ProgressService',
@@ -155,6 +157,7 @@ export class GeneralViewModel {
private sdcConfig:IAppConfigurtaion,
private $state:ng.ui.IStateService,
private ModalsHandler:ModalsHandler,
+ private modalServiceSdcUI: SdcUiServices.ModalService,
private EventListenerService:EventListenerService,
private Notification:any,
private progressService:ProgressService,
@@ -277,28 +280,40 @@ export class GeneralViewModel {
if (resource.resourceType === ResourceType.VF && !resource.csarUUID) {
this.$scope.isShowFileBrowse = true;
}
- } else if(this.$scope.component.isService()){
+ } else if (this.$scope.component.isService()) {
let service: Service = <Service>this.$scope.component;
console.log(service.name + ": " + service.csarUUID);
if (service.importedFile) {
this.$scope.isShowFileBrowse = true;
(<Service>this.$scope.component).ecompGeneratedNaming = true;
let blob = this.FileUtils.base64toBlob(service.importedFile.base64, "zip");
- new ServiceCsarReader().read(blob).then((serviceCsar) => {
- serviceCsar.serviceMetadata.contactId = this.cacheService.get("user").userId;
- (<Service>this.$scope.component).setComponentMetadata(serviceCsar.serviceMetadata);
- (<Service>this.$scope.component).model = serviceCsar.serviceMetadata.model;
- this.$scope.onModelChange();
- this.$scope.componentCategories.selectedCategory = serviceCsar.serviceMetadata.selectedCategory;
- this.$scope.onCategoryChange();
- serviceCsar.extraServiceMetadata.forEach((value: string, key: string) => {
- if(this.getMetadataKey(key)) {
- (<Service>this.$scope.component).categorySpecificMetadata[key] = value;
- }
+ new ServiceCsarReader().read(blob).then(
+ (serviceCsar) => {
+ serviceCsar.serviceMetadata.contactId = this.cacheService.get("user").userId;
+ (<Service>this.$scope.component).setComponentMetadata(serviceCsar.serviceMetadata);
+ (<Service>this.$scope.component).model = serviceCsar.serviceMetadata.model;
+ this.$scope.onModelChange();
+ this.$scope.componentCategories.selectedCategory = serviceCsar.serviceMetadata.selectedCategory;
+ this.$scope.onCategoryChange();
+ serviceCsar.extraServiceMetadata.forEach((value: string, key: string) => {
+ if (this.getMetadataKey(key)) {
+ (<Service>this.$scope.component).categorySpecificMetadata[key] = value;
+ }
+ });
+ (<Service>this.$scope.component).derivedFromGenericType = serviceCsar.substitutionNodeType;
+ this.$scope.onBaseTypeChange();
+ },
+ (error) => {
+ const errorMsg = this.$filter('translate')('IMPORT_FAILURE_MESSAGE_TEXT');
+ console.error(errorMsg, error);
+ const errorDetails = {
+ 'Error': error.reason,
+ 'Details': error.message
+ };
+ this.modalServiceSdcUI.openErrorDetailModal('Error', this.$filter('translate')('IMPORT_FAILURE_MESSAGE_TEXT'),
+ 'error-modal', errorDetails);
+ this.$state.go('dashboard');
});
- (<Service>this.$scope.component).derivedFromGenericType = serviceCsar.substitutionNodeType;
- this.$scope.onBaseTypeChange();
- });
}
if (this.$scope.isEditMode() && service.serviceType == 'Service' && !service.csarUUID) {
this.$scope.isShowFileBrowse = true;
diff --git a/catalog-ui/src/assets/languages/en_US.json b/catalog-ui/src/assets/languages/en_US.json
index 586717a03c..13c8669dee 100644
--- a/catalog-ui/src/assets/languages/en_US.json
+++ b/catalog-ui/src/assets/languages/en_US.json
@@ -565,5 +565,7 @@
"CAP_VALID_SOURCE": "Valid Sources",
"VALUE_LABEL": "Value",
"VALUE_EXPRESSION_LABEL": "Value Expression",
- "OPERATOR_LABEL": "Operator"
+ "OPERATOR_LABEL": "Operator",
+ "=========== SERVICE IMPORT ===========": "",
+ "IMPORT_FAILURE_MESSAGE_TEXT": "Import Failure - error reading CSAR"
}