summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java37
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java7
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java4
-rw-r--r--src/main/resources/application.properties2
4 files changed, 45 insertions, 5 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
index ffc9b8e28..f1cfd18f3 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
@@ -61,6 +61,8 @@ public class DcaeInventoryServices {
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
public static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
+ public static final String DCAE_INVENTORY_RETRY_INTERVAL = "dcae.intentory.retry.interval";
+ public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";
public static final String DCAE_TYPE_NAME = "typeName";
public static final String DCAE_TYPE_ID = "typeId";
@Autowired
@@ -78,7 +80,7 @@ public class DcaeInventoryServices {
* @throws ParseException
* In case of DCAE Json parse exception
*/
- public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException {
+ public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException, InterruptedException {
String artifactName = cldsModel.getControlName();
DcaeEvent dcaeEvent = new DcaeEvent();
DcaeInventoryResponse dcaeResponse = null;
@@ -159,7 +161,7 @@ public class DcaeInventoryServices {
* In case of issues with the Json parsing
*/
public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
- throws IOException, ParseException {
+ throws IOException, ParseException, InterruptedException {
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");
String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName="
@@ -167,7 +169,8 @@ public class DcaeInventoryServices {
String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString;
logger.info("Dcae Inventory Service full url - " + fullUrl);
String dcaeInventoryResponse = null;
- String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);
+
+ String responseStr = queryDCAEInventory (fullUrl);
JSONParser parser = new JSONParser();
Object obj0 = parser.parse(responseStr);
JSONObject jsonObj = (JSONObject) obj0;
@@ -185,6 +188,34 @@ public class DcaeInventoryServices {
return JacksonUtils.getObjectMapperInstance().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);
}
+ private String queryDCAEInventory (String fullUrl) throws IOException, InterruptedException {
+ int retryInterval = 0;
+ int retryLimit = 1;
+ if (refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT) != null) {
+ retryLimit = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT));
+ }
+ if (refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL) != null) {
+ retryInterval = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL));
+ }
+
+ int i = 0;
+ while (i < retryLimit) {
+ i++;
+ try {
+ return DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);
+ } catch (BadRequestException e) {
+ if (i == retryLimit) {
+ // reach the retry limit, but still failed to connect to DCAE
+ throw e;
+ } else {
+ // wait for a while and try to connect to DCAE again
+ Thread.sleep(retryInterval);
+ }
+ }
+ }
+ // normally it should not go to this branch. It should either return the DCAE query result, or throw exception
+ return null;
+ }
/**
* Inserts a new DCAEServiceType or updates an existing instance. If the
* typeName is same second time(already exists) then the
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
index 627bc72ad..a44f86771 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
@@ -27,6 +27,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.util.Date;
+import java.util.concurrent.ThreadLocalRandom;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
@@ -200,6 +201,10 @@ public class SdcSingleController {
public void treatNotification(INotificationData iNotif) {
CsarHandler csar = null;
try {
+ // wait for a random time, so that 2 running Clamp will not treat the same Notification at the same time
+ int i = ThreadLocalRandom.current().nextInt(1, 5);
+ Thread.sleep(i * 1000);
+
logger.info("Notification received for service UUID:" + iNotif.getServiceUUID());
this.changeControllerStatus(SdcSingleControllerStatus.BUSY);
csar = new CsarHandler(iNotif, this.sdcConfig.getSdcControllerName(),
@@ -241,6 +246,8 @@ public class SdcSingleController {
this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),
sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,
e.getMessage(), System.currentTimeMillis());
+ } catch (InterruptedException e) {
+ logger.error("Interrupt exception caught during the notification processing", e);
} catch (RuntimeException e) {
logger.error("Unexpected exception caught during the notification processing", e);
} finally {
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
index 91c0b6a64..cb0da0aa0 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
@@ -97,7 +97,7 @@ public class CsarInstallerImpl implements CsarInstaller {
createFakeCldsModel(csar, createFakeCldsTemplate(csar, this.searchForRightMapping(csar)), serviceTypeId);
} catch (IOException e) {
throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e);
- } catch (ParseException e) {
+ } catch (ParseException | InterruptedException e) {
throw new SdcArtifactInstallerException("Exception caught during the Dcae query to get ServiceTypeId", e);
}
}
@@ -151,7 +151,7 @@ public class CsarInstallerImpl implements CsarInstaller {
return policyNameList.get(0);
}
- private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException {
+ private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException, InterruptedException {
return dcaeInventoryService.getDcaeInformation(csar.getBlueprintArtifactName(),
csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid()).getTypeId();
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 5f6a0d659..646c57700 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -191,6 +191,8 @@ clamp.config.clds.service.cache.invalidate.after.seconds=120
#DCAE Inventory Url Properties
clamp.config.dcae.inventory.url=http://dcae.api.simpledemo.onap.org:8080
+clamp.config.dcae.intentory.retry.interval=10000
+clamp.config.dcae.intentory.retry.limit=3
#DCAE Dispatcher Url Properties
clamp.config.dcae.dispatcher.url=http://dcae.api.simpledemo.onap.org:8080