aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java
diff options
context:
space:
mode:
Diffstat (limited to 'asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java238
1 files changed, 120 insertions, 118 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java
index 8daa708ee7..c98fb9b619 100644
--- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java
@@ -55,59 +55,56 @@ import org.springframework.stereotype.Component;
@Component
public class BpmnInstaller {
- protected static final Logger logger = LoggerFactory.getLogger(BpmnInstaller.class);
- private static final String BPMN_SUFFIX = ".bpmn";
- private static final String CAMUNDA_URL = "mso.camundaURL";
- private static final String CREATE_DEPLOYMENT_PATH = "/sobpmnengine/deployment/create";
-
- @Autowired
- private Environment env;
-
- public void installBpmn(String csarFilePath) {
- logger.info("Deploying BPMN files from {}", csarFilePath);
- try {
- ZipInputStream csarFile = new ZipInputStream(new FileInputStream(Paths.get(csarFilePath).normalize().toString()));
- ZipEntry entry = csarFile.getNextEntry();
-
- while (entry != null) {
- String name = entry.getName();
- if (name.endsWith(BPMN_SUFFIX)) {
- logger.debug("Attempting to deploy BPMN file: {}", name);
- try {
- Path p = Paths.get(name);
- String fileName = p.getFileName().toString();
- extractBpmnFileFromCsar(csarFile, fileName);
- HttpResponse response = sendDeploymentRequest(fileName);
- logger.debug("Response status line: {}", response.getStatusLine());
- logger.debug("Response entity: {}", response.getEntity().toString());
- if (response.getStatusLine().getStatusCode() != 200) {
- logger.debug("Failed deploying BPMN {}", name);
- logger
- .error("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), name, fileName,
- Integer.toString(response.getStatusLine().getStatusCode()), ErrorCode.DataError.getValue(),
- "ASDC BPMN deploy failed");
- }
- else {
- logger.debug("Successfully deployed to Camunda: {}", name);
- }
- }
- catch (Exception e) {
- logger.debug("Exception :", e);
- logger
- .error("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), name, e.getMessage(),
- ErrorCode.DataError.getValue(), "ASDC BPMN deploy failed");
- }
- }
- entry = csarFile.getNextEntry();
- }
- csarFile.close();
- } catch (IOException ex) {
- logger.debug("Exception :", ex);
- logger.error("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), csarFilePath,
- ex.getMessage(), ErrorCode.DataError.getValue(), "ASDC reading CSAR with workflows failed");
- }
- return;
- }
+ protected static final Logger logger = LoggerFactory.getLogger(BpmnInstaller.class);
+ private static final String BPMN_SUFFIX = ".bpmn";
+ private static final String CAMUNDA_URL = "mso.camundaURL";
+ private static final String CREATE_DEPLOYMENT_PATH = "/sobpmnengine/deployment/create";
+
+ @Autowired
+ private Environment env;
+
+ public void installBpmn(String csarFilePath) {
+ logger.info("Deploying BPMN files from {}", csarFilePath);
+ try {
+ ZipInputStream csarFile =
+ new ZipInputStream(new FileInputStream(Paths.get(csarFilePath).normalize().toString()));
+ ZipEntry entry = csarFile.getNextEntry();
+
+ while (entry != null) {
+ String name = entry.getName();
+ if (name.endsWith(BPMN_SUFFIX)) {
+ logger.debug("Attempting to deploy BPMN file: {}", name);
+ try {
+ Path p = Paths.get(name);
+ String fileName = p.getFileName().toString();
+ extractBpmnFileFromCsar(csarFile, fileName);
+ HttpResponse response = sendDeploymentRequest(fileName);
+ logger.debug("Response status line: {}", response.getStatusLine());
+ logger.debug("Response entity: {}", response.getEntity().toString());
+ if (response.getStatusLine().getStatusCode() != 200) {
+ logger.debug("Failed deploying BPMN {}", name);
+ logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(),
+ name, fileName, Integer.toString(response.getStatusLine().getStatusCode()),
+ ErrorCode.DataError.getValue(), "ASDC BPMN deploy failed");
+ } else {
+ logger.debug("Successfully deployed to Camunda: {}", name);
+ }
+ } catch (Exception e) {
+ logger.debug("Exception :", e);
+ logger.error("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), name,
+ e.getMessage(), ErrorCode.DataError.getValue(), "ASDC BPMN deploy failed");
+ }
+ }
+ entry = csarFile.getNextEntry();
+ }
+ csarFile.close();
+ } catch (IOException ex) {
+ logger.debug("Exception :", ex);
+ logger.error("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), csarFilePath,
+ ex.getMessage(), ErrorCode.DataError.getValue(), "ASDC reading CSAR with workflows failed");
+ }
+ return;
+ }
public boolean containsWorkflows(String csarFilePath) {
boolean workflowsInCsar = false;
@@ -121,74 +118,79 @@ public class BpmnInstaller {
}
}
} catch (Exception e) {
- logger.debug("Exception :", e);
- logger.error("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), csarFilePath, e.getMessage(),
- ErrorCode.DataError.getValue(), "ASDC Unable to check CSAR entries");
- }
+ logger.debug("Exception :", e);
+ logger.error("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), csarFilePath, e.getMessage(),
+ ErrorCode.DataError.getValue(), "ASDC Unable to check CSAR entries");
+ }
return workflowsInCsar;
}
- protected HttpResponse sendDeploymentRequest(String bpmnFileName) throws Exception {
- HttpClient client = HttpClientBuilder.create().build();
- URI deploymentUri = new URI(this.env.getProperty(CAMUNDA_URL) + CREATE_DEPLOYMENT_PATH);
- HttpPost post = new HttpPost(deploymentUri);
- RequestConfig requestConfig =
- RequestConfig.custom().setSocketTimeout(1000000).setConnectTimeout(1000).setConnectionRequestTimeout(1000).build();
- post.setConfig(requestConfig);
- HttpEntity requestEntity = buildMimeMultipart(bpmnFileName);
- post.setEntity(requestEntity);
- return client.execute(post);
- }
-
- protected HttpEntity buildMimeMultipart(String bpmnFileName) throws Exception {
- FileInputStream bpmnFileStream = new FileInputStream (Paths.get(System.getProperty("mso.config.path"),"ASDC", bpmnFileName).normalize().toString());
+ protected HttpResponse sendDeploymentRequest(String bpmnFileName) throws Exception {
+ HttpClient client = HttpClientBuilder.create().build();
+ URI deploymentUri = new URI(this.env.getProperty(CAMUNDA_URL) + CREATE_DEPLOYMENT_PATH);
+ HttpPost post = new HttpPost(deploymentUri);
+ RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(1000000).setConnectTimeout(1000)
+ .setConnectionRequestTimeout(1000).build();
+ post.setConfig(requestConfig);
+ HttpEntity requestEntity = buildMimeMultipart(bpmnFileName);
+ post.setEntity(requestEntity);
+ return client.execute(post);
+ }
+
+ protected HttpEntity buildMimeMultipart(String bpmnFileName) throws Exception {
+ FileInputStream bpmnFileStream = new FileInputStream(
+ Paths.get(System.getProperty("mso.config.path"), "ASDC", bpmnFileName).normalize().toString());
- byte[] bytesToSend = IOUtils.toByteArray(bpmnFileStream);
- HttpEntity requestEntity = MultipartEntityBuilder.create()
- .addPart(FormBodyPartBuilder.create()
- .setName("deployment-name")
- .setBody(new StringBody("MSO Sample 1", ContentType.TEXT_PLAIN))
- .setField("Content-Disposition", String.format("form-data; name=\"%s\"", "deployment-name"))
- .build())
- .addPart(FormBodyPartBuilder.create()
- .setName("enable-duplicate-filtering")
- .setBody(new StringBody("false", ContentType.TEXT_PLAIN))
- .setField("Content-Disposition", String.format("form-data; name=\"%s\"", "enable-duplicate-filtering"))
- .build())
- .addPart(FormBodyPartBuilder.create()
- .setName("deplpy-changed-only")
- .setBody(new StringBody("false", ContentType.TEXT_PLAIN))
- .setField("Content-Disposition", String.format("form-data; name=\"%s\"", "deploy-changed-only"))
- .build())
- .addPart(FormBodyPartBuilder.create()
- .setName("deployment-source")
- .setBody(new StringBody("local", ContentType.TEXT_PLAIN))
- .setField("Content-Disposition", String.format("form-data; name=\"%s\"", "deployment-source"))
- .build())
- .addPart(FormBodyPartBuilder.create()
- .setName(bpmnFileName)
- .setBody(new ByteArrayBody(bytesToSend, ContentType.create("octet"), bpmnFileName))
- .setField("Content-Disposition", String.format("form-data; name=\"%s\"; filename=\"%s\"; size=%d", bpmnFileName, bpmnFileName, bytesToSend.length))
- .build())
- .build();
-
- IOUtils.closeQuietly(bpmnFileStream);
- return requestEntity;
- }
-
- /* protected void extractBpmnFileFromCsar(ZipInputStream zipIn, String fileName) throws IOException */
- protected void extractBpmnFileFromCsar(ZipInputStream zipIn, String fileName) {
- String filePath = Paths.get(System.getProperty("mso.config.path"), "ASDC", fileName).normalize().toString();
- /* BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(filePath)); */
- try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(filePath))){
- byte[] bytesIn = new byte[4096];
- int read = 0;
- while ((read = zipIn.read(bytesIn)) != -1) {
- outputStream.write(bytesIn, 0, read);
- }
- /* outputStream.close(); */
- } catch (IOException e) {
- logger.error("Unable to open file.", e);
+ byte[] bytesToSend = IOUtils.toByteArray(bpmnFileStream);
+ HttpEntity requestEntity =
+ MultipartEntityBuilder.create()
+ .addPart(FormBodyPartBuilder.create().setName("deployment-name")
+ .setBody(new StringBody("MSO Sample 1", ContentType.TEXT_PLAIN))
+ .setField("Content-Disposition",
+ String.format("form-data; name=\"%s\"", "deployment-name"))
+ .build())
+ .addPart(FormBodyPartBuilder.create().setName("enable-duplicate-filtering")
+ .setBody(new StringBody("false", ContentType.TEXT_PLAIN))
+ .setField("Content-Disposition",
+ String.format("form-data; name=\"%s\"", "enable-duplicate-filtering"))
+ .build())
+ .addPart(FormBodyPartBuilder.create().setName("deplpy-changed-only")
+ .setBody(new StringBody("false", ContentType.TEXT_PLAIN))
+ .setField("Content-Disposition",
+ String.format("form-data; name=\"%s\"", "deploy-changed-only"))
+ .build())
+ .addPart(FormBodyPartBuilder.create().setName("deployment-source")
+ .setBody(new StringBody("local", ContentType.TEXT_PLAIN))
+ .setField("Content-Disposition",
+ String.format("form-data; name=\"%s\"", "deployment-source"))
+ .build())
+ .addPart(
+ FormBodyPartBuilder.create().setName(bpmnFileName)
+ .setBody(new ByteArrayBody(bytesToSend, ContentType.create("octet"),
+ bpmnFileName))
+ .setField("Content-Disposition",
+ String.format("form-data; name=\"%s\"; filename=\"%s\"; size=%d",
+ bpmnFileName, bpmnFileName, bytesToSend.length))
+ .build())
+ .build();
+
+ IOUtils.closeQuietly(bpmnFileStream);
+ return requestEntity;
+ }
+
+ /* protected void extractBpmnFileFromCsar(ZipInputStream zipIn, String fileName) throws IOException */
+ protected void extractBpmnFileFromCsar(ZipInputStream zipIn, String fileName) {
+ String filePath = Paths.get(System.getProperty("mso.config.path"), "ASDC", fileName).normalize().toString();
+ /* BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(filePath)); */
+ try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(filePath))) {
+ byte[] bytesIn = new byte[4096];
+ int read = 0;
+ while ((read = zipIn.read(bytesIn)) != -1) {
+ outputStream.write(bytesIn, 0, read);
+ }
+ /* outputStream.close(); */
+ } catch (IOException e) {
+ logger.error("Unable to open file.", e);
}
- }
+ }
}