summaryrefslogtreecommitdiffstats
path: root/asdc-controller/src
diff options
context:
space:
mode:
Diffstat (limited to 'asdc-controller/src')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java26
-rw-r--r--asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java31
-rw-r--r--asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java5
3 files changed, 61 insertions, 1 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java
index 0fc94c8bd6..7f1c1968c1 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java
@@ -20,6 +20,8 @@
package org.onap.so.asdc.activity;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.onap.so.logger.LoggingAnchor;
@@ -27,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
+import org.apache.http.HttpStatus;
import org.onap.so.asdc.activity.beans.ActivitySpec;
import org.onap.so.asdc.activity.beans.Input;
import org.onap.so.asdc.activity.beans.Output;
@@ -59,6 +62,11 @@ public class DeployActivitySpecs {
String hostname = env.getProperty(SDC_ENDPOINT);
logger.debug("{} {}", "SDC ActivitySpec endpoint: ", hostname);
if (hostname == null || hostname.isEmpty()) {
+ logger.warn("The hostname for SDC activities deployment is not configured in SO");
+ return;
+ }
+ if (!checkHttpOk(hostname)) {
+ logger.warn("The sdc end point is not alive");
return;
}
List<org.onap.so.db.catalog.beans.ActivitySpec> activitySpecsFromCatalog = activitySpecRepository.findAll();
@@ -135,4 +143,22 @@ public class DeployActivitySpecs {
activitySpec.setOutputs(outputs);
return;
}
+
+ public boolean checkHttpOk(String host) {
+ URL url = null;
+ boolean isOk = false;
+
+ int responseCode = 0;
+ try {
+ url = new URL(host);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ responseCode = connection.getResponseCode();
+ } catch (Exception e) {
+ logger.warn("Exception on connecting to SDC WFD endpoint: " + e.getMessage());
+ }
+ if (responseCode == HttpStatus.SC_OK) {
+ isOk = true;
+ }
+ return isOk;
+ }
}
diff --git a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java
index 81977da278..b41fbaf658 100644
--- a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java
+++ b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsITTest.java
@@ -22,7 +22,10 @@ package org.onap.asdc.activity;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import org.junit.Test;
@@ -73,4 +76,32 @@ public class DeployActivitySpecsITTest extends BaseTest {
deployActivitySpecs.deployActivities();
assertTrue(activitySpecCreateResponse.getId().equals("testActivityId"));
}
+
+ @Test
+ public void deployActivitySpecsIT_SDCEndpointDown_Test() throws Exception {
+ ActivitySpecCreateResponse activitySpecCreateResponse = new ActivitySpecCreateResponse();
+ activitySpecCreateResponse.setId("testActivityId");
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Accept", MediaType.APPLICATION_JSON);
+ headers.set("Content-Type", MediaType.APPLICATION_JSON);
+
+ ObjectMapper mapper = new ObjectMapper();
+ String body = mapper.writeValueAsString(activitySpecCreateResponse);
+
+ wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(org.springframework.http.HttpStatus.OK.value()).withBody(body)));
+
+ when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://localhost:8090");
+
+ String urlPath = "/v1.0/activity-spec/testActivityId/versions/latest/actions";
+
+ wireMockServer.stubFor(
+ put(urlPathMatching(urlPath)).willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withStatus(org.springframework.http.HttpStatus.OK.value())));
+
+ deployActivitySpecs.deployActivities();
+ verify(0, putRequestedFor(urlEqualTo(urlPath)));
+ }
+
}
diff --git a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java
index aae5e5dc53..7a876a67a2 100644
--- a/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java
+++ b/asdc-controller/src/test/java/org/onap/asdc/activity/DeployActivitySpecsTest.java
@@ -30,6 +30,7 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.asdc.activity.ActivitySpecsActions;
import org.onap.so.asdc.activity.DeployActivitySpecs;
@@ -54,6 +55,7 @@ public class DeployActivitySpecsTest {
protected ActivitySpecsActions activitySpecsActions;
@InjectMocks
+ @Spy
private DeployActivitySpecs deployActivitySpecs;
@Test
@@ -68,7 +70,8 @@ public class DeployActivitySpecsTest {
List<org.onap.so.db.catalog.beans.ActivitySpec> catalogActivitySpecList =
new ArrayList<org.onap.so.db.catalog.beans.ActivitySpec>();
catalogActivitySpecList.add(catalogActivitySpec);
- when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("testEndpoint");
+ when(env.getProperty("mso.asdc.config.activity.endpoint")).thenReturn("http://testEndpoint");
+ doReturn(true).when(deployActivitySpecs).checkHttpOk("http://testEndpoint");
when(activitySpecRepository.findAll()).thenReturn(catalogActivitySpecList);
doReturn("testActivityId").when(activitySpecsActions).createActivitySpec(Mockito.any(), Mockito.any());
doReturn(true).when(activitySpecsActions).certifyActivitySpec(Mockito.any(), Mockito.any());