2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.client;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import java.io.IOException;
30 import java.security.GeneralSecurityException;
31 import java.util.List;
33 import org.apache.camel.Exchange;
34 import org.apache.camel.Handler;
35 import org.apache.commons.codec.DecoderException;
36 import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
37 import org.onap.clamp.clds.client.req.sdc.SdcReq;
38 import org.onap.clamp.clds.model.DcaeEvent;
39 import org.onap.clamp.clds.model.prop.Global;
40 import org.onap.clamp.clds.model.prop.ModelProperties;
41 import org.onap.clamp.clds.model.refprop.RefProp;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.stereotype.Component;
46 * Send control loop model to dcae proxy.
49 public class SdcSendReqDelegate {
51 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcSendReqDelegate.class);
52 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
54 private SdcCatalogServices sdcCatalogServices;
56 private SdcReq sdcReq;
58 private RefProp refProp;
61 * Perform activity. Send to sdc proxy.
63 * @param camelExchange
64 * The camel object that contains all fields
65 * @throws DecoderException
66 * In case of issues with password decryption
67 * @throws GeneralSecurityException
68 * In case of issues with password decryption
70 * In case of issues with file opening
73 public void execute(Exchange camelExchange) throws GeneralSecurityException, DecoderException, IOException {
74 String controlName = (String) camelExchange.getProperty("controlName");
75 String baseUrl = refProp.getStringValue("sdc.serviceUrl");
76 String artifactLabel = sdcReq
77 .normalizeResourceInstanceName(refProp.getStringValue("sdc.artifactLabel") + "-" + controlName);
78 String locationArtifactLabel = sdcReq
79 .normalizeResourceInstanceName(refProp.getStringValue("sdc.locationArtifactLabel") + "-" + controlName);
80 String artifactType = refProp.getStringValue("sdc.artifactType");
81 String locationArtifactType = refProp.getStringValue("sdc.locationArtifactType");
82 String userid = (String) camelExchange.getProperty("userid");
83 String docText = (String) camelExchange.getProperty("docText");
84 String artifactName = (String) camelExchange.getProperty("controlName") + DcaeEvent.ARTIFACT_NAME_SUFFIX;
85 camelExchange.setProperty("artifactName", artifactName);
86 ModelProperties prop = ModelProperties.create(camelExchange);
87 String bluprintPayload;
88 bluprintPayload = sdcReq.formatBlueprint(prop, docText);
89 // no need to upload blueprint for Holmes, thus blueprintPayload for
91 if (!bluprintPayload.isEmpty()) {
92 String formattedSdcReq = sdcReq.formatSdcReq(bluprintPayload, artifactName, artifactLabel, artifactType);
93 if (formattedSdcReq != null) {
94 camelExchange.setProperty("formattedArtifactReq", formattedSdcReq.getBytes());
96 Global globalProps = prop.getGlobal();
97 if (globalProps != null && globalProps.getService() != null) {
98 String serviceInvariantUUID = globalProps.getService();
99 camelExchange.setProperty("serviceInvariantUUID", serviceInvariantUUID);
101 List<String> sdcReqUrlsList = sdcReq.getSdcReqUrlsList(prop, baseUrl);
102 String sdcLocationsPayload = sdcReq.formatSdcLocationsReq(prop, artifactName);
103 String locationArtifactName = (String) camelExchange.getProperty("controlName") + "-location.json";
104 String formattedSdcLocationReq = sdcReq.formatSdcReq(sdcLocationsPayload, locationArtifactName,
105 locationArtifactLabel, locationArtifactType);
106 if (formattedSdcLocationReq != null) {
107 camelExchange.setProperty("formattedLocationReq", formattedSdcLocationReq.getBytes());
109 sdcCatalogServices.uploadToSdc(prop, userid, sdcReqUrlsList, formattedSdcReq, formattedSdcLocationReq,
110 artifactName, locationArtifactName);