diff options
Diffstat (limited to 'bpmn/so-bpmn-building-blocks/src')
10 files changed, 277 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java b/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java new file mode 100644 index 0000000000..db1f7cb6f9 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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========================================================= + */ + +package org.onap.so.bpmn.infrastructure.bpmn.activity; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +import javax.ws.rs.core.UriBuilder; + +import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.springframework.stereotype.Component; + +@Component +public class DeployActivitySpecs { + private static final String ACTIVITY_FILE_LOCATION = "src/main/resources/ActivitySpec/"; + private static final String ACTIVITY_SPEC_URI = "/activityspec-api/v1.0/activity-spec"; + private static final String CONTENT_TYPE_JSON = "application/json"; + + public static void main(String[] args) throws Exception { + + if (args == null || args.length == 0) { + System.out.println("Please specify hostname argument"); + return; + } + + String hostname = args[0]; + + File dir = new File(ACTIVITY_FILE_LOCATION); + if (!dir.isDirectory()) { + System.out.println("ActivitySpec store is not a directory"); + return; + } + + for (File f : dir.listFiles()) { + String activitySpecName = f.getName(); + String errorMessage = deployActivitySpec(hostname, activitySpecName); + if (errorMessage == null) { + System.out.println("Deployed Activity Spec: " + activitySpecName); + } + else { + System.out.println("Error deploying Activity Spec: " + activitySpecName + " : " + errorMessage); + } + } + return; + } + + protected static String deployActivitySpec(String hostname, String activitySpecName) throws Exception { + String payload = new String(Files.readAllBytes(Paths.get(ACTIVITY_FILE_LOCATION + activitySpecName))); + try { + HttpClient client = HttpClientBuilder.create().build(); + + String url = UriBuilder.fromUri(hostname).path(ACTIVITY_SPEC_URI).build().toString(); + HttpPost post = new HttpPost(url); + + StringEntity input = new StringEntity(payload); + input.setContentType(CONTENT_TYPE_JSON); + post.setEntity(input); + + HttpResponse response = client.execute(post); + StatusLine statusLine = response.getStatusLine(); + + if (statusLine != null) { + if (statusLine.getStatusCode() != 200) { + return (statusLine.toString()); + } + else { + return null; + } + } + else { + return("Empty response from the remote endpoint"); + } + + } catch (Exception e) { + return e.getMessage(); + } + + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFHealthCheckActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFHealthCheckActivitySpec.json new file mode 100644 index 0000000000..9f278b20c1 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFHealthCheckActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFHealthCheckActivity", + "description": "Activity to HealthCheck VNF", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFQuiesceTrafficActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFQuiesceTrafficActivitySpec.json new file mode 100644 index 0000000000..c64098dcea --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFQuiesceTrafficActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFQuiesceTrafficActivity", + "description": "Activity to QuiesceTraffic on VNF", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFResumeTrafficActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFResumeTrafficActivitySpec.json new file mode 100644 index 0000000000..6527f2e66d --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFResumeTrafficActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFResumeTrafficActivity", + "description": "Activity to ResumeTraffic on VNF", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFSetInMaintFlagActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFSetInMaintFlagActivitySpec.json new file mode 100644 index 0000000000..8f3211c9a9 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFSetInMaintFlagActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFSetInMaintFlagActivity", + "description": "Activity to Set InMaint Flag in A&AI", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUnsetInMaintFlagActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUnsetInMaintFlagActivitySpec.json new file mode 100644 index 0000000000..1c3f862fec --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUnsetInMaintFlagActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFUnsetInMaintFlagActivity", + "description": "Activity to Unset InMaint Flag in A&AI", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradePostCheckActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradePostCheckActivitySpec.json new file mode 100644 index 0000000000..722fd6e667 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradePostCheckActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFUpgradePostCheckActivity", + "description": "Activity to UpgradePostCheck on VNF", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradePreCheckActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradePreCheckActivitySpec.json new file mode 100644 index 0000000000..bae912ee3b --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradePreCheckActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFUpgradePreCheckActivity", + "description": "Activity to UpgradePreCheck on VNF", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradeSoftwareActivitySpec.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradeSoftwareActivitySpec.json new file mode 100644 index 0000000000..606fa6cd1f --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/VNFUpgradeSoftwareActivitySpec.json @@ -0,0 +1,14 @@ +{ + "name": "VNFUpgradeSoftwareActivity", + "description": "Activity to UpgradeSoftware on VNF", + "categoryList": [ + "VNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecsTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecsTest.java new file mode 100644 index 0000000000..77146593ba --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecsTest.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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========================================================= + */ + +package org.onap.so.bpmn.infrastructure.bpmn.activity; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.message.BasicHttpResponse; +import org.junit.Test; + +public class DeployActivitySpecsTest { + private static final String RESULT_STRING = "HTTP/1.1 404 "; + private static final String HOSTNAME = "http://localhost:8080"; + + @Test + public void DeployActivitySpecsMain_Test() throws Exception { + ProtocolVersion protocolVersion = new ProtocolVersion("", 1, 1); + HttpResponse response = new BasicHttpResponse(protocolVersion, 1, ""); + response.setStatusCode(404); + response.setStatusLine(protocolVersion, 1, ""); + HttpClient clientMock = mock(HttpClient.class); + when(clientMock.execute(any(HttpPost.class))).thenReturn(response); + String[] args = new String[] {HOSTNAME}; + DeployActivitySpecs.main(args); + } + + @Test + public void DeployActivitySpec_Test() throws Exception { + ProtocolVersion protocolVersion = new ProtocolVersion("", 1, 1); + HttpResponse response = new BasicHttpResponse(protocolVersion, 1, ""); + response.setStatusCode(404); + response.setStatusLine(protocolVersion, 1, ""); + HttpClient clientMock = mock(HttpClient.class); + when(clientMock.execute(any(HttpPost.class))).thenReturn(response); ; + String result = DeployActivitySpecs.deployActivitySpec(HOSTNAME, "VNFQuiesceTrafficActivitySpec.json"); + assertEquals(result, RESULT_STRING); + } +} |