summaryrefslogtreecommitdiffstats
path: root/asdc-controller/src/main/java/org
diff options
context:
space:
mode:
authorElena Kuleshov <evn@att.com>2019-04-07 17:20:03 -0400
committerElena Kuleshov <evn@att.com>2019-04-09 02:43:23 -0400
commit65e1358e0b4e4f44969db81bcb347e6722d81b08 (patch)
tree88944bec0fb55cdf9a98b9ab920fa30fcc07a364 /asdc-controller/src/main/java/org
parented66a29ce8e0068740466e13fa6517791cce9aeb (diff)
Implement interface to SDC for ActivitySpec
Implement interface to SDC for ActivitySpec publishing Change-Id: I4991d312906d7675651b30b08469a4b6cc2e9623 Issue-ID: SO-1740 Signed-off-by: Kuleshov, Elena <evn@att.com>
Diffstat (limited to 'asdc-controller/src/main/java/org')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java123
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java67
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpec.java99
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpecCreateResponse.java61
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Input.java61
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Output.java73
6 files changed, 484 insertions, 0 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java
new file mode 100644
index 0000000000..c80e84b574
--- /dev/null
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/ActivitySpecsActions.java
@@ -0,0 +1,123 @@
+/*-
+ * ============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.asdc.activity;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.http.HttpStatus;
+import org.apache.http.entity.ContentType;
+import org.onap.so.asdc.activity.beans.ActivitySpec;
+import org.onap.so.asdc.activity.beans.ActivitySpecCreateResponse;
+import org.onap.so.client.HttpClient;
+import org.onap.so.client.HttpClientFactory;
+import org.onap.so.utils.TargetEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.net.URL;
+
+@Component
+public class ActivitySpecsActions {
+
+ private static final String ACTIVITY_SPEC_URI = "/v1.0/activity-spec";
+ private static final String ACTIVITY_SPEC_URI_SUFFIX = "/versions/latest/actions";
+ private static final String CERTIFY_ACTIVITY_PAYLOAD = "{\"action\": \"CERTIFY\"}";
+
+ private final HttpClientFactory httpClientFactory = new HttpClientFactory();
+ protected static final Logger logger = LoggerFactory.getLogger(ActivitySpecsActions.class);
+
+ public String createActivitySpec(String hostname, ActivitySpec activitySpec) {
+ if (activitySpec == null) {
+ return null;
+ }
+
+ String activitySpecId = null;
+
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(Include.NON_NULL);
+ String payload = mapper.writer().writeValueAsString(activitySpec);
+
+ String urlString = UriBuilder.fromUri(hostname).path(ACTIVITY_SPEC_URI).build().toString();
+ URL url = new URL(urlString);
+
+ HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.SDC);
+ httpClient.addAdditionalHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
+
+ Response response = httpClient.post(payload);
+
+ int statusCode = response.getStatus();
+ if (statusCode != HttpStatus.SC_OK) {
+ logger.warn("{} {} {}", "Error creating activity spec", activitySpec.getName(), statusCode);
+ } else {
+ if (response.getEntity() != null) {
+ ActivitySpecCreateResponse activitySpecCreateResponse =
+ response.readEntity(ActivitySpecCreateResponse.class);
+ if (activitySpecCreateResponse != null) {
+ activitySpecId = activitySpecCreateResponse.getId();
+ } else {
+ logger.warn("{} {}", "Unable to read activity spec", activitySpec.getName());
+ }
+ } else {
+ logger.warn("{} {}", "No activity spec response returned", activitySpec.getName());
+ }
+ }
+ } catch (Exception e) {
+ logger.warn("{} {}", "Exception creating activitySpec", e.getMessage());
+ }
+
+ return activitySpecId;
+ }
+
+ public boolean certifyActivitySpec(String hostname, String activitySpecId) {
+ boolean certificationResult = false;
+ if (activitySpecId == null) {
+ return false;
+ }
+
+ try {
+ String path = ACTIVITY_SPEC_URI + "/" + activitySpecId + ACTIVITY_SPEC_URI_SUFFIX;
+
+ String urlString = UriBuilder.fromUri(hostname).path(path).build().toString();
+ URL url = new URL(urlString);
+
+ HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.SDC);
+ httpClient.addAdditionalHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
+
+ Response response = httpClient.put(CERTIFY_ACTIVITY_PAYLOAD);
+
+ int statusCode = response.getStatus();
+
+ if (statusCode != HttpStatus.SC_OK) {
+ logger.warn("{} {} {}", "Error certifying activity", activitySpecId, statusCode);
+ } else {
+ certificationResult = true;
+ }
+
+ } catch (Exception e) {
+ logger.warn("{} {}", "Exception certifying activitySpec", e.getMessage());
+ }
+
+ return certificationResult;
+ }
+}
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
new file mode 100644
index 0000000000..46d0f78e35
--- /dev/null
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java
@@ -0,0 +1,67 @@
+/*-
+ * ============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.asdc.activity;
+
+import javax.annotation.PostConstruct;
+import java.util.ArrayList;
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+import org.onap.so.asdc.activity.beans.ActivitySpec;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+public class DeployActivitySpecs {
+ @Autowired
+ private ActivitySpecsActions activitySpecsActions;
+
+ @Autowired
+ private Environment env;
+
+ private static final String SDC_ENDPOINT = "mso.asdc.config.activity.endpoint";
+
+ protected static final Logger logger = LoggerFactory.getLogger(DeployActivitySpecs.class);
+
+ public void deployActivities() throws Exception {
+ String hostname = this.env.getProperty(SDC_ENDPOINT);
+ List<ActivitySpec> activitySpecs = new ArrayList<ActivitySpec>();
+
+ // Initialize activitySpecs from Catalog DB
+
+ for (ActivitySpec activitySpec : activitySpecs) {
+ String activitySpecId = activitySpecsActions.createActivitySpec(hostname, activitySpec);
+ if (activitySpecId != null) {
+ logger.info("{} {}", "Successfully created activitySpec", activitySpec.getName());
+ boolean certificationResult = activitySpecsActions.certifyActivitySpec(hostname, activitySpecId);
+ if (certificationResult) {
+ logger.info("{} {}", "Successfully certified activitySpec", activitySpec.getName());
+ } else {
+ logger.info("{} {}", "Failed to certify activitySpec", activitySpec.getName());
+ }
+ } else {
+ logger.info("{} {}", "Failed to create activitySpec", activitySpec.getName());
+ }
+ }
+ }
+}
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpec.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpec.java
new file mode 100644
index 0000000000..e7d1ff15ab
--- /dev/null
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpec.java
@@ -0,0 +1,99 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.asdc.activity.beans;
+
+import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"name", "description", "categoryList", "inputs", "outputs"})
+public class ActivitySpec {
+
+ @JsonProperty("name")
+ private String name;
+ @JsonProperty("description")
+ private String description;
+ @JsonProperty("categoryList")
+ private List<String> categoryList = null;
+ @JsonProperty("inputs")
+ private List<Input> inputs = null;
+ @JsonProperty("outputs")
+ private List<Output> outputs = null;
+
+ @JsonProperty("name")
+ public String getName() {
+ return name;
+ }
+
+ @JsonProperty("name")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @JsonProperty("description")
+ public String getDescription() {
+ return description;
+ }
+
+ @JsonProperty("description")
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @JsonProperty("categoryList")
+ public List<String> getCategoryList() {
+ return categoryList;
+ }
+
+ @JsonProperty("categoryList")
+ public void setCategoryList(List<String> categoryList) {
+ this.categoryList = categoryList;
+ }
+
+ @JsonProperty("inputs")
+ public List<Input> getInputs() {
+ return inputs;
+ }
+
+ @JsonProperty("inputs")
+ public void setInputs(List<Input> inputs) {
+ this.inputs = inputs;
+ }
+
+ @JsonProperty("outputs")
+ public List<Output> getOutputs() {
+ return outputs;
+ }
+
+ @JsonProperty("outputs")
+ public void setOutputs(List<Output> outputs) {
+ this.outputs = outputs;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("name", name).append("description", description)
+ .append("categoryList", categoryList).append("inputs", inputs).append("outputs", outputs).toString();
+ }
+
+}
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpecCreateResponse.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpecCreateResponse.java
new file mode 100644
index 0000000000..13844257b6
--- /dev/null
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/ActivitySpecCreateResponse.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.asdc.activity.beans;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"id", "versionId"})
+public class ActivitySpecCreateResponse {
+
+ @JsonProperty("id")
+ private String id;
+ @JsonProperty("versionId")
+ private String versionId;
+
+ @JsonProperty("id")
+ public String getId() {
+ return id;
+ }
+
+ @JsonProperty("id")
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @JsonProperty("versionId")
+ public String getVersionId() {
+ return versionId;
+ }
+
+ @JsonProperty("versionId")
+ public void setVersionId(String versionId) {
+ this.versionId = versionId;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("id", id).append("versionId", versionId).toString();
+ }
+
+}
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Input.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Input.java
new file mode 100644
index 0000000000..3359d1df2d
--- /dev/null
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Input.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.asdc.activity.beans;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"name", "type"})
+public class Input {
+
+ @JsonProperty("name")
+ private String name;
+ @JsonProperty("type")
+ private String type;
+
+ @JsonProperty("name")
+ public String getName() {
+ return name;
+ }
+
+ @JsonProperty("name")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @JsonProperty("type")
+ public String getType() {
+ return type;
+ }
+
+ @JsonProperty("type")
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("name", name).append("type", type).toString();
+ }
+
+}
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Output.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Output.java
new file mode 100644
index 0000000000..1e3d2e4dd2
--- /dev/null
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/beans/Output.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.asdc.activity.beans;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"name", "type", "value"})
+public class Output {
+
+ @JsonProperty("name")
+ private String name;
+ @JsonProperty("type")
+ private String type;
+ @JsonProperty("value")
+ private String value;
+
+ @JsonProperty("name")
+ public String getName() {
+ return name;
+ }
+
+ @JsonProperty("name")
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @JsonProperty("type")
+ public String getType() {
+ return type;
+ }
+
+ @JsonProperty("type")
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @JsonProperty("value")
+ public String getValue() {
+ return value;
+ }
+
+ @JsonProperty("value")
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("name", name).append("type", type).append("value", value).toString();
+ }
+
+}