aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ArtifactMetadata.java
blob: e41d8d75480366fe51f450768c7c61a5ba66b4a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.be.externalapi.servlet.representation;

public class ArtifactMetadata {
    private String artifactName;
    private String artifactType;
    private String artifactURL;
    private String artifactDescription;
    private Integer artifactTimeout;
    private String artifactChecksum;
    private String artifactUUID;
    private String artifactVersion;
    private String generatedFromUUID;
    private String artifactLabel;
    private String artifactGroupType;

    public String getArtifactName() {
        return artifactName;
    }

    public void setArtifactName(String artifactName) {
        this.artifactName = artifactName;
    }

    public String getArtifactType() {
        return artifactType;
    }

    public void setArtifactType(String artifactType) {
        this.artifactType = artifactType;
    }

    public String getArtifactURL() {
        return artifactURL;
    }

    public void setArtifactURL(String artifactURL) {
        this.artifactURL = artifactURL;
    }

    public String getArtifactDescription() {
        return artifactDescription;
    }

    public void setArtifactDescription(String artifactDescription) {
        this.artifactDescription = artifactDescription;
    }

    public Integer getArtifactTimeout() {
        return artifactTimeout;
    }

    public void setArtifactTimeout(Integer artifactTimeout) {
        this.artifactTimeout = artifactTimeout;
    }

    public String getArtifactChecksum() {
        return artifactChecksum;
    }

    public void setArtifactChecksum(String artifactChecksum) {
        this.artifactChecksum = artifactChecksum;
    }

    public String getArtifactUUID() {
        return artifactUUID;
    }

    public void setArtifactUUID(String artifactUUID) {
        this.artifactUUID = artifactUUID;
    }

    public String getArtifactVersion() {
        return artifactVersion;
    }

    public void setArtifactVersion(String artifactVersion) {
        this.artifactVersion = artifactVersion;
    }

    public String getGeneratedFromUUID() {
        return generatedFromUUID;
    }

    public void setGeneratedFromUUID(String generatedFromUUID) {
        this.generatedFromUUID = generatedFromUUID;
    }

    public String getArtifactLabel() {
        return artifactLabel;
    }

    public void setArtifactLabel(String artifactLabel) {
        this.artifactLabel = artifactLabel;
    }

    public String getArtifactGroupType() {
        return artifactGroupType;
    }

    public void setArtifactGroupType(String artifactGroupType) {
        this.artifactGroupType = artifactGroupType;
    }

}
class="n">String vnfmId, InstantiateVnfRequest driverRequest, String vnfInstanceId, String jobId, NslcmMgmrInf nslcmMgmr, CatalogMgmrInf catalogMgmr, CbamMgmrInf cbamMgmr, Driver2CbamRequestConverter requestConverter, VnfmJobExecutionRepository dbManager) { this.driverRequest = driverRequest; this.vnfInstanceId = vnfInstanceId; this.jobId = jobId; this.nslcmMgmr = nslcmMgmr; this.catalogMgmr = catalogMgmr; this.cbamMgmr = cbamMgmr; this.requestConverter = requestConverter; this.jobDbMgmr = dbManager; this.vnfmId = vnfmId; } public void run() { //step 1 handle vnf package handleVnfPackage(); handleGrant(); handleModify(); try { //step 5: instantiate vnf CBAMInstantiateVnfResponse cbamInstantiateResponse = handleInstantiate(); handleNotify(cbamInstantiateResponse); } catch (Exception e) { logger.error("InstantiateVnfContinueRunnable --> handleInstantiate or handleNotify error.", e); } } private void handleNotify(CBAMInstantiateVnfResponse cbamInstantiateResponse) { try { logger.info("Start to notify LCM the instantiation result"); NslcmNotifyLCMEventsRequest nslcmNotifyReq = buildNslcmNotifyLCMEventsRequest(cbamInstantiateResponse); nslcmMgmr.notifyVnf(nslcmNotifyReq, vnfmId, vnfInstanceId); logger.info("End to notify LCM the instantiation result"); } catch (Exception e) { logger.error("InstantiateVnfContinueRunnable --> handleNotify error.", e); } } private CBAMInstantiateVnfResponse handleInstantiate() throws Exception { CBAMInstantiateVnfRequest instantiateReq = requestConverter.instantiateRequestConvert(driverRequest, null, null, null); CBAMInstantiateVnfResponse cbamInstantiateResponse = cbamMgmr.instantiateVnf(instantiateReq, vnfInstanceId); handleCbamInstantiateResponse(cbamInstantiateResponse, jobId); return cbamInstantiateResponse; } private void handleModify() { try { CBAMModifyVnfRequest modifyReq = generateModifyVnfRequest(); cbamMgmr.modifyVnf(modifyReq, vnfInstanceId); } catch (Exception e) { logger.error("InstantiateVnfContinueRunnable --> handleModify error.", e); } } private void handleGrant(){ try { NslcmGrantVnfRequest grantRequest = buildNslcmGrantVnfRequest(); nslcmMgmr.grantVnf(grantRequest); } catch (Exception e) { logger.error("InstantiateVnfContinueRunnable --> handleGrant error.", e); } } private CBAMModifyVnfRequest generateModifyVnfRequest() throws IOException{ String filePath = "/etc/vnfpkginfo/cbam_extension.json"; String fileContent = CommonUtil.getJsonStrFromFile(filePath); CBAMModifyVnfRequest req = gson.fromJson(fileContent, CBAMModifyVnfRequest.class); return req; } private void handleVnfPackage() { Executors.newSingleThreadExecutor().execute(new Runnable() { @Override public void run() { try { //step 1: query vnfPackage uri -- download package -- extract it -- upload CBAM package to CBAM VnfPackageInfo vnfPackageInfo = catalogMgmr.queryVnfPackage(driverRequest.getVnfPackageId()); String packageUrl = vnfPackageInfo.getDownloadUri(); String saveDir = "/service/vnfPackage"; String packageFileName = packageUrl.substring(packageUrl.lastIndexOf("/")); Process process = Runtime.getRuntime().exec("mkdir -p " + saveDir); process.waitFor(); if (HttpClientProcessorImpl.downLoadFromUrl(packageUrl, packageFileName, saveDir)) { logger.info("handleVnfPackage download file " + packageUrl + " is successful."); // File csarFile = new File(saveDir + "/" + packageFileName); // //extract package // ZipUtil.explode(csarFile); // csarFile.delete(); } } catch (Exception e) { logger.error("Error to handleVnfPackage from SDC", e); } } }); } private NslcmNotifyLCMEventsRequest buildNslcmNotifyLCMEventsRequest(CBAMInstantiateVnfResponse cbamInstantiateResponse) { NslcmNotifyLCMEventsRequest request = new NslcmNotifyLCMEventsRequest(); if(CommonEnum.OperationStatus.STARTED == cbamInstantiateResponse.getStatus()) { request.setStatus(CommonEnum.status.start); } else { request.setStatus(CommonEnum.status.result); //TODO the following are for the result // request.setAffectedVnfc(affectedVnfc); // request.setAffectedVI(affectedVI); // request.setAffectedVirtualStorage(affectedVirtualStorage); } request.setVnfInstanceId(vnfInstanceId); request.setOperation(CommonConstants.NSLCM_OPERATION_INSTANTIATE); request.setJobId(jobId); return request; } private NslcmGrantVnfRequest buildNslcmGrantVnfRequest() { NslcmGrantVnfRequest request = new NslcmGrantVnfRequest(); request.setVnfInstanceId(vnfInstanceId); request.setLifecycleOperation(LifecycleOperation.Instantiate); request.setJobId(jobId); ResourceDefinition resource = getFreeVnfResource(); List<ResourceDefinition> resourceList = new ArrayList<ResourceDefinition>(); resourceList.add(resource); request.setAddResource(resourceList); return request; } private ResourceDefinition getFreeVnfResource() { ResourceDefinition def = new ResourceDefinition(); def.setVnfInstanceId(vnfInstanceId); def.setVimId("001"); List<AddResource> resources = new ArrayList<>(); AddResource res = new AddResource(); res.setVdu("1"); res.setType("vdu"); res.setResourceDefinitionId(2); resources.add(res); def.setAddResource(resources); return def; } private void handleCbamInstantiateResponse(CBAMInstantiateVnfResponse cbamInstantiateResponse, String jobId) { VnfmJobExecutionInfo jobInfo = jobDbMgmr.findOne(Long.parseLong(jobId)); jobInfo.setVnfmExecutionId(cbamInstantiateResponse.getId()); if(CommonEnum.OperationStatus.FAILED == cbamInstantiateResponse.getStatus()){ jobInfo.setStatus(CommonConstants.CBAM_OPERATION_STATUS_ERROR); } jobDbMgmr.save(jobInfo); } }