diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2017-08-08 03:16:59 -0700 |
---|---|---|
committer | Sébastien Determe <sd378r@intl.att.com> | 2017-08-08 12:36:31 +0000 |
commit | bb03393b823bc2b1ec43be654e13b83a5a74a566 (patch) | |
tree | de84eda2d333e6a9a52e342a534f14cd658a6ec9 /src/main/java | |
parent | 50d34dacd85c7fdaf73ab9e970587243d6e79ebf (diff) |
Rework of the DCAE client
Rework of the DCAE client and javascripts/html pages of the designer
(part5)
Change-Id: I3e7b889e2112dc2745632a328a02c6c603ecc195
Issue-Id: CLAMP-1
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main/java')
8 files changed, 1068 insertions, 0 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java new file mode 100644 index 000000000..343391ebd --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java @@ -0,0 +1,321 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.client;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.stream.Collectors;
+
+import javax.net.ssl.HttpsURLConnection;
+
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.onap.clamp.clds.model.refprop.RefProp;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+/**
+ *
+ *
+ */
+public class DcaeDispatcherServices {
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeDispatcherServices.class);
+ protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+
+ @Autowired
+ private RefProp refProp;
+
+ /**
+ *
+ * @param deploymentId
+ * @return
+ * @throws Exception
+ */
+ public String deleteDeployment(String deploymentId) throws Exception {
+
+ String statusUrl = null;
+ InputStream in = null;
+ try {
+ String url = refProp.getStringValue("DCAE_DISPATCHER_URL") + "/dcae-deployments/" + deploymentId;
+ logger.info("Dcae Dispatcher url - " + url);
+ URL obj = new URL(url);
+ HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();
+ conn.setRequestMethod("DELETE");
+ int responseCode = conn.getResponseCode();
+
+ boolean requestFailed = true;
+ logger.info("responseCode=" + responseCode);
+ if (responseCode == 200 || responseCode == 202) {
+ requestFailed = false;
+ }
+
+ InputStream inStream = conn.getErrorStream();
+ if (inStream == null) {
+ inStream = conn.getInputStream();
+ }
+
+ String responseStr = null;
+ if (inStream != null) {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inStream));
+ String inputLine = null;
+ StringBuffer response = new StringBuffer();
+ while ((inputLine = bufferedReader.readLine()) != null) {
+ response.append(inputLine);
+ }
+ responseStr = response.toString();
+ }
+
+ if (responseStr != null) {
+ if (requestFailed) {
+ logger.error("requestFailed - responseStr=" + responseStr);
+ throw new Exception(responseStr);
+ }
+ }
+
+ logger.debug("response code " + responseCode);
+ in = conn.getInputStream();
+ logger.debug("res:" + responseStr);
+ JSONParser parser = new JSONParser();
+ Object obj0 = parser.parse(responseStr);
+ JSONObject jsonObj = (JSONObject) obj0;
+ JSONObject linksObj = (JSONObject) jsonObj.get("links");
+ statusUrl = (String) linksObj.get("status");
+ logger.debug("Status URL: " + statusUrl);
+
+ } catch (Exception e) {
+ logger.error(e.getClass().getName() + " " + e.getMessage());
+ throw e;
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+
+ return statusUrl;
+
+ }
+
+ /**
+ *
+ * @param statusUrl
+ * @return
+ * @throws Exception
+ */
+ public String getOperationStatus(String statusUrl) throws Exception {
+
+ String opStatus = null;
+ InputStream in = null;
+ try {
+ URL obj = new URL(statusUrl);
+ HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();
+ conn.setRequestMethod("GET");
+ int responseCode = conn.getResponseCode();
+ logger.debug("response code " + responseCode);
+ in = conn.getInputStream();
+ String res = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
+ JSONParser parser = new JSONParser();
+ Object obj0 = parser.parse(res);
+ JSONObject jsonObj = (JSONObject) obj0;
+ String operationType = (String) jsonObj.get("operationType");
+ String status = (String) jsonObj.get("status");
+ logger.debug("Operation Type " + operationType);
+ logger.debug("Status " + status);
+ opStatus = status;
+
+ } catch (Exception e) {
+ logger.debug(e.getClass().getName() + " " + e.getMessage());
+ logger.debug(e.getMessage()
+ + " : got exception while retrieving status, trying again until we get 200 response code");
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+
+ return opStatus;
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void getDeployments() throws Exception {
+ InputStream in = null;
+ try {
+ String url = refProp.getStringValue("DCAE_DISPATCHER_URL") + "/dcae-deployments";
+ logger.info("Dcae Dispatcher deployments url - " + url);
+ URL obj = new URL(url);
+ HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();
+ conn.setRequestMethod("GET");
+ int responseCode = conn.getResponseCode();
+ logger.debug("response code " + responseCode);
+ in = conn.getInputStream();
+ String res = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
+ logger.debug("res:" + res);
+ } catch (Exception e) {
+ logger.error("Exception occurred during DCAE communication", e);
+ throw e;
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ /**
+ * Returns status URL for deployment operation
+ *
+ * @param deploymentId
+ * @param serviceTypeId
+ * @return
+ * @throws Exception
+ */
+ public String createNewDeployment(String deploymentId, String serviceTypeId) throws Exception {
+
+ String statusUrl = null;
+ InputStream inStream = null;
+ BufferedReader in = null;
+ try {
+ String apiBodyString = "{\"serviceTypeId\": \"" + serviceTypeId + "\"}";
+ logger.info("Dcae api Body String - " + apiBodyString);
+ String url = refProp.getStringValue("DCAE_DISPATCHER_URL") + "/dcae-deployments/" + deploymentId;
+ logger.info("Dcae Dispatcher Service url - " + url);
+ URL obj = new URL(url);
+ HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();
+ conn.setRequestMethod("PUT");
+ conn.setRequestProperty("Content-Type", "application/json");
+ conn.setDoOutput(true);
+ try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
+ wr.writeBytes(apiBodyString);
+ wr.flush();
+ }
+
+ boolean requestFailed = true;
+ int responseCode = conn.getResponseCode();
+ logger.info("responseCode=" + responseCode);
+ if (responseCode == 200 || responseCode == 202) {
+ requestFailed = false;
+ }
+
+ inStream = conn.getErrorStream();
+ if (inStream == null) {
+ inStream = conn.getInputStream();
+ }
+
+ String responseStr = null;
+ if (inStream != null) {
+ in = new BufferedReader(new InputStreamReader(inStream));
+
+ String inputLine = null;
+
+ StringBuffer response = new StringBuffer();
+
+ while ((inputLine = in.readLine()) != null) {
+ response.append(inputLine);
+ }
+
+ responseStr = response.toString();
+ }
+
+ if (responseStr != null) {
+ if (requestFailed) {
+ logger.error("requestFailed - responseStr=" + responseStr);
+ throw new Exception(responseStr);
+ }
+ }
+
+ logger.debug("response code " + responseCode);
+ JSONParser parser = new JSONParser();
+ Object obj0 = parser.parse(responseStr);
+ JSONObject jsonObj = (JSONObject) obj0;
+ JSONObject linksObj = (JSONObject) jsonObj.get("links");
+ statusUrl = (String) linksObj.get("status");
+ logger.debug("Status URL: " + statusUrl);
+ } catch (Exception e) {
+ logger.error("Exception occurred during the DCAE communication", e);
+ throw e;
+ } finally {
+ if (inStream != null) {
+ inStream.close();
+ }
+ if (in != null) {
+ in.close();
+ }
+ }
+ return statusUrl;
+ }
+
+ /**
+ *
+ * @param deploymentId
+ * @param serviceTypeId
+ * @return
+ * @throws Exception
+ */
+ public String deleteExistingDeployment(String deploymentId, String serviceTypeId) throws Exception {
+
+ String statusUrl = null;
+ InputStream in = null;
+ try {
+ String apiBodyString = "{\"serviceTypeId\": \"" + serviceTypeId + "\"}";
+ logger.debug(apiBodyString);
+ String url = refProp.getStringValue("DCAE_DISPATCHER_URL") + "/dcae-deployments/" + deploymentId;
+ logger.info("Dcae Dispatcher deployments url - " + url);
+ URL obj = new URL(url);
+ HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();
+ conn.setRequestMethod("DELETE");
+ conn.setRequestProperty("Content-Type", "application/json");
+ conn.setDoOutput(true);
+ DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
+ wr.writeBytes(apiBodyString);
+ wr.flush();
+
+ int responseCode = conn.getResponseCode();
+ logger.debug("response code " + responseCode);
+ in = conn.getInputStream();
+ String res = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
+ logger.debug("res:" + res);
+ JSONParser parser = new JSONParser();
+ Object obj0 = parser.parse(res);
+ JSONObject jsonObj = (JSONObject) obj0;
+ JSONObject linksObj = (JSONObject) jsonObj.get("links");
+ statusUrl = (String) linksObj.get("status");
+ logger.debug("Status URL: " + statusUrl);
+ } catch (Exception e) {
+ logger.error("Exception occurred during DCAE communication", e);
+ throw e;
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ return statusUrl;
+ }
+
+}
\ No newline at end of file diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java new file mode 100644 index 000000000..3dfe9fecb --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java @@ -0,0 +1,181 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.client;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+
+import javax.ws.rs.BadRequestException;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.model.CldsEvent;
+import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.model.DcaeEvent;
+import org.onap.clamp.clds.model.prop.Global;
+import org.onap.clamp.clds.model.prop.ModelProperties;
+import org.onap.clamp.clds.model.refprop.RefProp;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class DcaeInventoryServices {
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);
+ protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+
+ @Autowired
+ private RefProp refProp;
+
+ @Autowired
+ private CldsDao cldsDao;
+
+ @Autowired
+ private SdcCatalogServices sdcCatalogServices;
+
+ public void setEventInventory(CldsModel cldsModel, String userId) throws Exception {
+ String artifactName = cldsModel.getControlName();
+ DcaeEvent dcaeEvent = new DcaeEvent();
+ String isDcaeInfoAvailable = null;
+ if (artifactName != null) {
+ artifactName = artifactName + ".yml";
+ }
+ try {
+ /*
+ * Below are the properties required for calling the dcae inventory
+ * url call
+ */
+ ModelProperties prop = new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), null, false, "{}",
+ cldsModel.getPropText());
+ Global global = prop.getGlobal();
+ String invariantServiceUuid = global.getService();
+ List<String> resourceUuidList = global.getResourceVf();
+ String serviceUuid = sdcCatalogServices.getServiceUuidFromServiceInvariantId(invariantServiceUuid);
+ String resourceUuid = "";
+ if (resourceUuidList != null && resourceUuidList.size() > 0) {
+ resourceUuid = resourceUuidList.get(0).toString();
+ }
+ /* Invemtory service url is called in this method */
+ isDcaeInfoAvailable = getDcaeInformation(artifactName, serviceUuid, resourceUuid);
+
+ /* set dcae events */
+ dcaeEvent.setArtifactName(artifactName);
+ dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);
+
+ } catch (JsonProcessingException e) {
+ // exception
+ logger.error("JsonProcessingException" + e);
+ } catch (IOException e) {
+
+ // exception
+ logger.error("IOException :" + e);
+ }
+ /* Null whether the DCAE has items lenght or not */
+ if (isDcaeInfoAvailable != null) {
+ /* Inserting Event in to DB */
+ logger.info(isDcaeInfoAvailable);
+ JSONParser parser = new JSONParser();
+ Object obj0 = parser.parse(isDcaeInfoAvailable);
+ JSONObject jsonObj = (JSONObject) obj0;
+ String oldTypeId = cldsModel.getTypeId();
+ String newTypeId = "";
+ if (jsonObj.get("typeId") != null) {
+ newTypeId = jsonObj.get("typeId").toString();
+ cldsModel.setTypeId(jsonObj.get("typeId").toString());
+ }
+ // cldsModel.setTypeName(cldsModel.getControlName().toString()+".yml");
+ if (jsonObj.get("typeName") != null) {
+ cldsModel.setTypeName(jsonObj.get("typeName").toString());
+ }
+ if(oldTypeId == null || !oldTypeId.equalsIgnoreCase(newTypeId)){
+ CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),
+ CldsEvent.ACTION_STATE_RECEIVED, null);
+ }
+ cldsModel.save(cldsDao, userId);
+ } else {
+ logger.info(cldsModel.getName() + " Model is not present in Dcae Inventory Service.");
+ }
+ }
+
+ public String getDcaeInformation(String artifactName, String serviceUUID, String resourceUUID)
+ throws IOException, ParseException {
+ String queryString = "?sdcResourceId=" + resourceUUID + "&sdcServiceId=" + serviceUUID + "&typeName="
+ + artifactName;
+ String fullUrl = refProp.getStringValue("DCAE_INVENTORY_URL") + "/dcae-service-types" + queryString;
+ logger.info("Dcae Inventory Service full url - " + fullUrl);
+ String daceInventoryResponse = null;
+ URL inventoryUrl = new URL(fullUrl);
+
+ HttpURLConnection conn = (HttpURLConnection) inventoryUrl.openConnection();
+ conn.setRequestMethod("GET");
+ boolean requestFailed = true;
+ int responseCode = conn.getResponseCode();
+ if (responseCode == 200) {
+ requestFailed = false;
+ }
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ String inputLine = null;
+ StringBuffer response = new StringBuffer();
+ String responseStr = null;
+ while ((inputLine = in.readLine()) != null) {
+ response.append(inputLine);
+ }
+ in.close();
+ responseStr = response.toString();
+ if (responseStr != null) {
+ if (requestFailed) {
+ logger.error("requestFailed - responseStr=" + response);
+ throw new BadRequestException(responseStr);
+ }
+ }
+ String jsonResponseString = response.toString();
+ JSONParser parser = new JSONParser();
+ Object obj0 = parser.parse(jsonResponseString);
+
+ JSONObject jsonObj = (JSONObject) obj0;
+
+ Long totalCount = (Long) jsonObj.get("totalCount");
+
+ int numServices = totalCount.intValue();
+ if (numServices == 0) {
+ daceInventoryResponse = null;
+ } else if (numServices > 0) {
+ JSONArray itemsArray = (JSONArray) jsonObj.get("items");
+ JSONObject dcaeServiceType0 = (JSONObject) itemsArray.get(0);
+ daceInventoryResponse = dcaeServiceType0.toString();
+ logger.info(daceInventoryResponse.toString());
+ }
+ return daceInventoryResponse;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsHealthCheck.java b/src/main/java/org/onap/clamp/clds/model/CldsHealthCheck.java new file mode 100644 index 000000000..9a5e5a534 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsHealthCheck.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * 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============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +public class CldsHealthCheck { + + private String healthCheckComponent; + + public String getHealthCheckComponent() { + return healthCheckComponent; + } + + public void setHealthCheckComponent(String healthCheckComponent) { + this.healthCheckComponent = healthCheckComponent; + } + + private String healthCheckStatus; + private String description; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getHealthCheckStatus() { + return healthCheckStatus; + } + + public void setHealthCheckStatus(String healthCheckStatus) { + this.healthCheckStatus = healthCheckStatus; + } + +} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsInfo.java b/src/main/java/org/onap/clamp/clds/model/CldsInfo.java new file mode 100644 index 000000000..9dc0f870d --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsInfo.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * 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============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +public class CldsInfo { + + private String userName; + private String cldsVersion; + private boolean permissionReadCl; + private boolean permissionUpdateCl; + private boolean permissionReadTemplate; + private boolean permissionUpdateTemplate; + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getCldsVersion() { + return cldsVersion; + } + + public void setCldsVersion(String cldsVersion) { + this.cldsVersion = cldsVersion; + } + + public boolean isPermissionReadCl() { + return permissionReadCl; + } + + public void setPermissionReadCl(boolean permissionReadCl) { + this.permissionReadCl = permissionReadCl; + } + + public boolean isPermissionUpdateCl() { + return permissionUpdateCl; + } + + public void setPermissionUpdateCl(boolean permissionUpdateCl) { + this.permissionUpdateCl = permissionUpdateCl; + } + + public boolean isPermissionReadTemplate() { + return permissionReadTemplate; + } + + public void setPermissionReadTemplate(boolean permissionReadTemplate) { + this.permissionReadTemplate = permissionReadTemplate; + } + + public boolean isPermissionUpdateTemplate() { + return permissionUpdateTemplate; + } + + public void setPermissionUpdateTemplate(boolean permissionUpdateTemplate) { + this.permissionUpdateTemplate = permissionUpdateTemplate; + } + +} diff --git a/src/main/java/org/onap/clamp/clds/model/CldsVfKPIData.java b/src/main/java/org/onap/clamp/clds/model/CldsVfKPIData.java new file mode 100644 index 000000000..62e676f08 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/CldsVfKPIData.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * 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============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model; + +import java.io.Serializable; + +public class CldsVfKPIData implements Serializable { + + private static final long serialVersionUID = 9067755871527776380L; + + private String nfNamingCode; + private String nfNamingValue; + + private String fieldPath; + private String fieldPathValue; + + private String thresholdName; + private String thresholdValue; + + public String getNfNamingCode() { + return nfNamingCode; + } + + public void setNfNamingCode(String nfNamingCode) { + this.nfNamingCode = nfNamingCode; + } + + public String getNfNamingValue() { + return nfNamingValue; + } + + public void setNfNamingValue(String nfNamingValue) { + this.nfNamingValue = nfNamingValue; + } + + public String getFieldPath() { + return fieldPath; + } + + public void setFieldPath(String fieldPath) { + this.fieldPath = fieldPath; + } + + public String getFieldPathValue() { + return fieldPathValue; + } + + public void setFieldPathValue(String fieldPathValue) { + this.fieldPathValue = fieldPathValue; + } + + public String getThresholdName() { + return thresholdName; + } + + public void setThresholdName(String thresholdName) { + this.thresholdName = thresholdName; + } + + public String getThresholdValue() { + return thresholdValue; + } + + public void setThresholdValue(String thresholdValue) { + this.thresholdValue = thresholdValue; + } + +} diff --git a/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java new file mode 100644 index 000000000..6142e9e63 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * 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============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model.prop; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Parse Policy json properties. + * + * Example json: + * {"Policy_1e33tn8":{"PolicyTest1":[{"name":"pname","value":"PolicyTest1"},{ + * "name":"pid","value":"1"},{"name":"timeout","value":"345"},{ + * "policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name": + * "maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name" + * :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name": + * "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name": + * "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name": + * "parentPolicy","value":[""]}]]}],"PolicyTest2":[{"name":"pname","value": + * "PolicyTest2"},{"name":"pid","value":"2"},{"name":"timeout","value":"345"},{ + * "policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name": + * "maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name" + * :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name": + * "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name": + * "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name": + * "parentPolicy","value":[""]}]]}]}} f + * + */ +public class PolicyChain { + + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyChain.class); + protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); + + private String policyId; + private Integer timeout; + private List<PolicyItem> policyItems; + + public PolicyChain(JsonNode node) { + + policyId = ModelElement.getValueByName(node, "pid"); + timeout = ModelElement.getIntValueByName(node, "timeout"); + + // process policy configurations + JsonNode policyNode = node.get(node.size() - 1).get("policyConfigurations"); + Iterator<JsonNode> itr = policyNode.elements(); + policyItems = new ArrayList<PolicyItem>(); + while (itr.hasNext()) { + policyItems.add(new PolicyItem(itr.next())); + } + } + + /** + * @return the policyId + */ + public String getPolicyId() { + return policyId; + } + + /** + * @return the timeout + */ + public Integer getTimeout() { + return timeout; + } + + /** + * @return the policyItems + */ + public List<PolicyItem> getPolicyItems() { + return policyItems; + } + +} diff --git a/src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java b/src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java new file mode 100644 index 000000000..de98333a1 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/prop/ResourceGroup.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * 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============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model.prop; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; + +/** + * Parse Resource Group json properties. + * + * Example json: + * {"StringMatch_0aji7go":{"Group1":[{"name":"rgname","value":"1493749598520"},{ + * "name":"rgfriendlyname","value":"Group1"},{"name":"policyName","value": + * "Policy1"},{"name":"policyId","value":"1"},{"serviceConfigurations":[[{"name" + * :"aaiMatchingFields","value":["complex.city","vserver.vserver-name"]},{"name" + * :"aaiSendFields","value":["complex.city","vserver.vserver-name"]},{"name": + * "eventSeverity","value":["OK"]},{"name":"eventSourceType","value":[""]},{ + * "name":"timeWindow","value":["100"]},{"name":"ageLimit","value":["100"]},{ + * "name":"createClosedLoopEventId","value":["Initial"]},{"name": + * "outputEventName","value":["ONSET"]}]]}],"Group2":[{"name":"rgname","value": + * "1493749665149"},{"name":"rgfriendlyname","value":"Group2"},{"name": + * "policyName","value":"Policy2"},{"name":"policyId","value":"2"},{ + * "serviceConfigurations":[[{"name":"aaiMatchingFields","value":[ + * "cloud-region.identity-url","vserver.vserver-name"]},{"name":"aaiSendFields", + * "value":["cloud-region.identity-url","vserver.vserver-name"]},{"name": + * "eventSeverity","value":["NORMAL"]},{"name":"eventSourceType","value":[""]},{ + * "name":"timeWindow","value":["1000"]},{"name":"ageLimit","value":["1000"]},{ + * "name":"createClosedLoopEventId","value":["Initial"]},{"name": + * "outputEventName","value":["ONSET"]}],[{"name":"aaiMatchingFields","value":[ + * "generic-vnf.vnf-name","vserver.vserver-name"]},{"name":"aaiSendFields", + * "value":["generic-vnf.vnf-name","vserver.vserver-name"]},{"name": + * "eventSeverity","value":["CRITICAL"]},{"name":"eventSourceType","value":[""]} + * ,{"name":"timeWindow","value":["3000"]},{"name":"ageLimit","value":["3000"]}, + * {"name":"createClosedLoopEventId","value":["Initial"]},{"name": + * "outputEventName","value":["ABATED"]}]]}]}} + * + */ +public class ResourceGroup { + + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(ResourceGroup.class); + protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); + + private String groupNumber; + private String policyId; + private List<ServiceConfiguration> serviceConfigurations; + + /** + * Parse String Match Resource Group given json node. + * + * @param modelBpmn + * @param modelJson + */ + public ResourceGroup(JsonNode node) { + + groupNumber = ModelElement.getValueByName(node, "rgname"); + policyId = ModelElement.getValueByName(node, "policyId"); + + // process Server_Configurations + JsonNode serviceConfigurationsNode = node.get(node.size() - 1).get("serviceConfigurations"); + Iterator<JsonNode> itr = serviceConfigurationsNode.elements(); + serviceConfigurations = new ArrayList<ServiceConfiguration>(); + while (itr.hasNext()) { + serviceConfigurations.add(new ServiceConfiguration(itr.next())); + } + } + + /** + * @return the groupNumber + */ + public String getGroupNumber() { + return groupNumber; + } + + /** + * @return the policyId + */ + public String getPolicyId() { + return policyId; + } + + /** + * @return the serviceConfigurations + */ + public List<ServiceConfiguration> getServiceConfigurations() { + return serviceConfigurations; + } + +} diff --git a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java new file mode 100644 index 000000000..c47400689 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java @@ -0,0 +1,124 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.UUID;
+
+import org.jboss.logging.MDC;
+
+public class LoggingUtils {
+
+ /**
+ * Set request related logging variables in thread local data via MDC
+ *
+ * @param service
+ * Service Name of API (ex. "PUT template")
+ * @param partner
+ * Partner name (client or user invoking API)
+ */
+ public static void setRequestContext(String service, String partner) {
+ MDC.put("RequestId", "clds-" + UUID.randomUUID().toString());
+ MDC.put("ServiceName", service);
+ MDC.put("PartnerName", partner);
+ }
+
+ /**
+ * Set time related logging variables in thread local data via MDC
+ *
+ * @param beginTimeStamp
+ * Start time
+ * @param endTimeStamp
+ * End time
+ */
+ public static void setTimeContext(Date beginTimeStamp, Date endTimeStamp) {
+ String beginTime = "";
+ String endTime = "";
+ String elapsedTime = "";
+
+ if (beginTimeStamp != null && endTimeStamp != null) {
+ elapsedTime = String.valueOf(endTimeStamp.getTime() - beginTimeStamp.getTime());
+ beginTime = generateTimestampStr(beginTimeStamp);
+ endTime = generateTimestampStr(endTimeStamp);
+ }
+
+ MDC.put("BeginTimestamp", beginTime);
+ MDC.put("EndTimestamp", endTime);
+ MDC.put("ElapsedTime", elapsedTime);
+ }
+
+ /**
+ * Set response related logging variables in thread local data via MDC
+ *
+ * @param code
+ * Response code ("0" indicates success)
+ * @param description
+ * Response description
+ * @param className
+ * class name of invoking class
+ */
+ public static void setResponseContext(String code, String description, String className) {
+ MDC.put("ResponseCode", code);
+ MDC.put("StatusCode", code.equals("0") ? "COMPLETE" : "ERROR");
+ MDC.put("ResponseDescription", description != null ? description : "");
+ MDC.put("ClassName", className != null ? className : "");
+ }
+
+ /**
+ * Set target related logging variables in thread local data via MDC
+ *
+ * @param targetEntity
+ * Target entity (an external/sub component, for ex. "sdc")
+ * @param targetServiceName
+ * Target service name (name of API invoked on target)
+ */
+ public static void setTargetContext(String targetEntity, String targetServiceName) {
+ MDC.put("TargetEntity", targetEntity != null ? targetEntity : "");
+ MDC.put("TargetServiceName", targetServiceName != null ? targetServiceName : "");
+ }
+
+ /**
+ * Set error related logging variables in thread local data via MDC
+ *
+ * @param code
+ * Error code
+ * @param description
+ * Error description
+ */
+ public static void setErrorContext(String code, String description) {
+ MDC.put("ErrorCode", code);
+ MDC.put("ErrorDescription", description != null ? description : "");
+ }
+
+ private static String generateTimestampStr(Date timeStamp) {
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ df.setTimeZone(tz);
+ return df.format(timeStamp);
+ }
+
+}
|