2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.asdc.tenantIsolation;
\r
23 import java.util.ArrayList;
\r
24 import java.util.HashMap;
\r
25 import java.util.Iterator;
\r
26 import java.util.List;
\r
27 import java.util.Map;
\r
29 import org.openecomp.mso.asdc.client.ASDCConfiguration;
\r
30 import org.openecomp.mso.client.aai.AAIObjectType;
\r
31 import org.openecomp.mso.client.aai.AAIResourcesClient;
\r
32 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
\r
33 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
\r
34 import org.openecomp.mso.client.aai.entities.uri.Depth;
\r
35 import org.openecomp.mso.db.catalog.CatalogDatabase;
\r
36 import org.openecomp.mso.db.catalog.beans.Service;
\r
37 import org.openecomp.mso.logger.MsoLogger;
\r
38 import org.openecomp.mso.properties.MsoJsonProperties;
\r
39 import org.openecomp.mso.properties.MsoPropertiesException;
\r
40 import org.openecomp.mso.properties.MsoPropertiesFactory;
\r
41 import org.openecomp.mso.requestsdb.WatchdogComponentDistributionStatus;
\r
42 import org.openecomp.mso.requestsdb.WatchdogComponentDistributionStatusDb;
\r
43 import org.openecomp.mso.requestsdb.WatchdogDistributionStatusDb;
\r
44 import org.openecomp.mso.requestsdb.WatchdogServiceModVerIdLookupDb;
\r
46 import com.fasterxml.jackson.databind.JsonNode;
\r
48 public class WatchdogDistribution {
\r
50 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC);
\r
51 private static final String MSO_PROP_ASDC = "MSO_PROP_ASDC";
\r
52 private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
\r
53 private WatchdogDistributionStatusDb watchdogDistDb;
\r
54 private WatchdogComponentDistributionStatusDb watchdogCompDistDb;
\r
55 private WatchdogServiceModVerIdLookupDb watchdogSerlookupDb;
\r
56 private CatalogDatabase catalogDb;
\r
57 private AAIResourcesClient aaiClient;
\r
58 //protected ASDCConfiguration asdcConfig;
\r
60 public String getOverallDistributionStatus(String distributionId) throws MsoPropertiesException, Exception {
\r
61 LOGGER.debug("Entered getOverallDistributionStatus method for distrubutionId: " + distributionId);
\r
63 String status = null;
\r
65 String distributionStatus = getWatchdogDistDb().getWatchdogDistributionIdStatus(distributionId);
\r
67 if(DistributionStatus.TIMEOUT.name().equalsIgnoreCase(distributionStatus)) {
\r
68 LOGGER.debug("Ignoring to update WatchdogDistributionStatus as distributionId: " + distributionId + " status is set to: " + distributionStatus);
\r
69 return DistributionStatus.TIMEOUT.name();
\r
71 List<WatchdogComponentDistributionStatus> results = getWatchdogCompDistDb().getWatchdogComponentDistributionStatus(distributionId);
\r
72 LOGGER.debug("Executed RequestDB getWatchdogComponentDistributionStatus for distrubutionId: " + distributionId);
\r
74 MsoJsonProperties properties = msoPropertiesFactory.getMsoJsonProperties(MSO_PROP_ASDC);
\r
76 //*************************************************************************************************************************************************
\r
77 //**** Compare config values verse DB watchdog component names to see if every component has reported status before returning final result back to ASDC
\r
78 //**************************************************************************************************************************************************
\r
80 //List<String> configNames = asdcConfig.getComponentNames();
\r
82 List<String> dbNames = watchdogCompDistDb.getWatchdogComponentNames(distributionId);
\r
84 boolean allComponentsComplete = true;
\r
86 JsonNode masterConfigNode = properties.getJsonRootNode().get("componentNames");
\r
88 if (masterConfigNode != null) {
\r
90 Iterator<JsonNode> config = masterConfigNode.elements();
\r
92 while( config.hasNext() ) {
\r
93 String name = (String)config.next().asText();
\r
95 boolean match = false;
\r
97 for(String dbName: dbNames){
\r
99 if(name.equals(dbName)){
\r
100 LOGGER.debug("Found componentName " + name + " in the WatchDog Component DB");
\r
107 LOGGER.debug(name + " has not be updated in the the WatchDog Component DB yet, so ending the loop");
\r
108 allComponentsComplete = false;
\r
116 if(allComponentsComplete) {
\r
117 //if(node.asInt() == results.size()) {
\r
118 LOGGER.debug("Components Size matched with the WatchdogComponentDistributionStatus results.");
\r
120 for(WatchdogComponentDistributionStatus componentDist : results) {
\r
121 String componentDistributionStatus = componentDist.getComponentDistributionStatus();
\r
122 LOGGER.debug("Component status: " + componentDistributionStatus + " on componentName: " + componentDist.getComponentName());
\r
123 if(componentDistributionStatus.equalsIgnoreCase("COMPONENT_DONE_ERROR")) {
\r
124 status = DistributionStatus.FAILURE.name();
\r
126 } else if(componentDistributionStatus.equalsIgnoreCase("COMPONENT_DONE_OK")) {
\r
127 status = DistributionStatus.SUCCESS.name();
\r
129 throw new Exception("Invalid Component distribution status: " + componentDistributionStatus);
\r
133 LOGGER.debug("Updating overall DistributionStatus to: " + status + " for distributionId: " + distributionId);
\r
134 getWatchdogDistDb().updateWatchdogDistributionIdStatus(distributionId, status);
\r
136 LOGGER.debug("Components Size Didn't match with the WatchdogComponentDistributionStatus results.");
\r
137 status = DistributionStatus.INCOMPLETE.name();
\r
141 } catch (MsoPropertiesException e) {
\r
142 String error = "Error occurred when trying to load MSOJson Properties.";
\r
143 LOGGER.debug(error);
\r
144 throw new MsoPropertiesException(e.getMessage());
\r
145 } catch (Exception e) {
\r
146 LOGGER.debug("Exception occurred on getOverallDistributionStatus : " + e.getMessage());
\r
147 throw new Exception(e);
\r
150 LOGGER.debug("Exciting getOverallDistributionStatus method in WatchdogDistribution");
\r
154 public void executePatchAAI(String distributionId, String serviceModelInvariantUUID, String distributionStatus) throws Exception {
\r
155 LOGGER.debug("Entered executePatchAAI method with distrubutionId: " + distributionId + " and distributionStatus: " + distributionStatus);
\r
158 String serviceModelVersionId = getWatchdogSerlookupDb().getWatchdogServiceModVerId(distributionId);
\r
159 LOGGER.debug("Executed RequestDB getWatchdogServiceModVerIdLookup with distributionId: " + distributionId + " and serviceModelVersionId: " + serviceModelVersionId);
\r
161 LOGGER.debug("ASDC Notification ServiceModelInvariantUUID : " + serviceModelInvariantUUID);
\r
163 if(serviceModelInvariantUUID == null) {
\r
164 String error = "No Service found with serviceModelInvariantUUID: " + serviceModelInvariantUUID;
\r
165 LOGGER.debug(error);
\r
166 throw new Exception(error);
\r
169 AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, serviceModelInvariantUUID, serviceModelVersionId);
\r
170 aaiUri.depth(Depth.ZERO); //Do not return relationships if any
\r
171 LOGGER.debug("Target A&AI Resource URI: " + aaiUri.build().toString());
\r
173 Map<String, String> payload = new HashMap<>();
\r
174 payload.put("distribution-status", distributionStatus);
\r
175 getAaiClient().update(aaiUri, payload);
\r
177 LOGGER.debug("A&AI UPDATE MODEL Version is success!");
\r
178 } catch (Exception e) {
\r
179 LOGGER.debug("Exception occurred on executePatchAAI : " + e.getMessage());
\r
180 throw new Exception(e);
\r
184 public WatchdogDistributionStatusDb getWatchdogDistDb() {
\r
185 if(watchdogDistDb == null) {
\r
186 watchdogDistDb = WatchdogDistributionStatusDb.getInstance();
\r
188 return watchdogDistDb;
\r
191 public void setWatchdogDistDb(WatchdogDistributionStatusDb watchdogDistDb) {
\r
192 this.watchdogDistDb = watchdogDistDb;
\r
195 public WatchdogComponentDistributionStatusDb getWatchdogCompDistDb() {
\r
196 if(watchdogCompDistDb == null) {
\r
197 watchdogCompDistDb = WatchdogComponentDistributionStatusDb.getInstance();
\r
199 return watchdogCompDistDb;
\r
202 public void setWatchdogCompDistDb(WatchdogComponentDistributionStatusDb watchdogCompDistDb) {
\r
203 this.watchdogCompDistDb = watchdogCompDistDb;
\r
206 public WatchdogServiceModVerIdLookupDb getWatchdogSerlookupDb() {
\r
207 if(watchdogSerlookupDb == null) {
\r
208 watchdogSerlookupDb = WatchdogServiceModVerIdLookupDb.getInstance();
\r
210 return watchdogSerlookupDb;
\r
213 public void setWatchdogSerlookupDb(WatchdogServiceModVerIdLookupDb watchdogSerlookupDb) {
\r
214 this.watchdogSerlookupDb = watchdogSerlookupDb;
\r
217 public CatalogDatabase getCatalogDb() {
\r
218 if(catalogDb == null) {
\r
219 catalogDb = CatalogDatabase.getInstance();
\r
224 public void setCatalogDb(CatalogDatabase catalogDb) {
\r
225 this.catalogDb = catalogDb;
\r
228 public AAIResourcesClient getAaiClient() {
\r
229 if(aaiClient == null) {
\r
230 aaiClient = new AAIResourcesClient();
\r
235 public void setAaiClient(AAIResourcesClient aaiClient) {
\r
236 this.aaiClient = aaiClient;
\r