aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy
diff options
context:
space:
mode:
authorArthur Martella <amartell@research.att.com>2017-09-08 13:27:46 -0400
committerArthur Martella <amartell@research.att.com>2017-09-08 13:32:24 -0400
commit62cd6aaaf74aa91ee0037c0e155c8e7284f07567 (patch)
tree68c0c53c9156f5aa3c6b3599ac940770f986633d /bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy
parentfa1a211d28a912892fcd888569df033900eb01ee (diff)
1710 Rebase - Second Attempt
This commit rebases changes from openecomp-mso/internal-staging-1710 up to and including this codecloud commit: 54483fc6606ddb1591a2e9da61bff8712325f924 Wed Sep 6 18:12:56 2017 -0400 Rebasing was done on a branch on top of this commit in so/master in ONAP: 93fbdfbe46104f8859d4754040f979cb7997c157 Thu Sep 7 16:42:59 2017 +0000 Change-Id: I4ad9abf40da32bf5bdca43e868b8fa2dbcd9dc59 Issue-id: SO-107 Signed-off-by: Arthur Martella <amartell@research.att.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/CommonObjectMapperProvider.java31
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/DecisionAttributes.java74
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/LoggingFilter.java109
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecision.java38
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecisionRequest.java38
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyRestClient.java69
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java76
7 files changed, 435 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/CommonObjectMapperProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/CommonObjectMapperProvider.java
new file mode 100644
index 0000000000..8e709f21b5
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/CommonObjectMapperProvider.java
@@ -0,0 +1,31 @@
+package org.openecomp.mso.client.policy;
+
+import javax.ws.rs.ext.ContextResolver;
+
+import javax.ws.rs.ext.Provider;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+@Provider
+public class CommonObjectMapperProvider implements ContextResolver<ObjectMapper> {
+
+ final ObjectMapper mapper;
+
+ public CommonObjectMapperProvider() {
+
+ mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(Include.NON_NULL);
+ mapper.enable(MapperFeature.USE_ANNOTATIONS);
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
+ }
+
+ @Override
+ public ObjectMapper getContext(Class<?> type) {
+ return mapper;
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/DecisionAttributes.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/DecisionAttributes.java
new file mode 100644
index 0000000000..2325955950
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/DecisionAttributes.java
@@ -0,0 +1,74 @@
+
+package org.openecomp.mso.client.policy;
+
+
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "ServiceType", "VNFType", "BB_ID", "WorkStep", "ErrorCode" })
+public class DecisionAttributes {
+
+ @JsonProperty("ServiceType")
+ private String serviceType;
+ @JsonProperty("VNFType")
+ private String vNFType;
+ @JsonProperty("BB_ID")
+ private String bbID;
+ @JsonProperty("WorkStep")
+ private String workStep;
+ @JsonProperty("ErrorCode")
+ private String errorCode;
+
+ @JsonProperty("ServiceType")
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ @JsonProperty("ServiceType")
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ @JsonProperty("VNFType")
+ public String getVNFType() {
+ return vNFType;
+ }
+
+ @JsonProperty("VNFType")
+ public void setVNFType(String vNFType) {
+ this.vNFType = vNFType;
+ }
+
+ @JsonProperty("BB_ID")
+ public String getBBID() {
+ return bbID;
+ }
+
+ @JsonProperty("BB_ID")
+ public void setBBID(String bBID) {
+ this.bbID = bBID;
+ }
+
+ @JsonProperty("WorkStep")
+ public String getWorkStep() {
+ return workStep;
+ }
+
+ @JsonProperty("WorkStep")
+ public void setWorkStep(String workStep) {
+ this.workStep = workStep;
+ }
+
+ @JsonProperty("ErrorCode")
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+ @JsonProperty("ErrorCode")
+ public void setErrorCode(String errorCode) {
+ this.errorCode = errorCode;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/LoggingFilter.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/LoggingFilter.java
new file mode 100644
index 0000000000..9a7c21fba1
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/LoggingFilter.java
@@ -0,0 +1,109 @@
+package org.openecomp.mso.client.policy;
+
+import java.io.BufferedInputStream;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.logging.Logger;
+import javax.annotation.Priority;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+@Priority(Integer.MIN_VALUE)
+public class LoggingFilter implements ClientRequestFilter, ClientResponseFilter, WriterInterceptor {
+
+ private static final Logger logger = Logger.getLogger(LoggingFilter.class.getName());
+ private static final String ENTITY_STREAM_PROPERTY = "LoggingFilter.entityStream";
+ private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
+ private final int maxEntitySize = 1024 * 8;
+
+ private void log(StringBuilder sb) {
+ logger.info(sb.toString());
+ }
+
+ private InputStream logInboundEntity(final StringBuilder b, InputStream stream, final Charset charset)
+ throws IOException {
+ if (!stream.markSupported()) {
+ stream = new BufferedInputStream(stream);
+ }
+ stream.mark(maxEntitySize + 1);
+ final byte[] entity = new byte[maxEntitySize + 1];
+ final int entitySize = stream.read(entity);
+ b.append(new String(entity, 0, Math.min(entitySize, maxEntitySize), charset));
+ if (entitySize > maxEntitySize) {
+ b.append("...more...");
+ }
+ b.append('\n');
+ stream.reset();
+ return stream;
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext) throws IOException {
+ if (requestContext.hasEntity()) {
+ final OutputStream stream = new LoggingStream(requestContext.getEntityStream());
+ requestContext.setEntityStream(stream);
+ requestContext.setProperty(ENTITY_STREAM_PROPERTY, stream);
+ }
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
+ final StringBuilder sb = new StringBuilder();
+ if (responseContext.hasEntity()) {
+ responseContext.setEntityStream(logInboundEntity(sb, responseContext.getEntityStream(), DEFAULT_CHARSET));
+ log(sb);
+ }
+
+ }
+
+ @Override
+ public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
+ final LoggingStream stream = (LoggingStream) context.getProperty(ENTITY_STREAM_PROPERTY);
+ context.proceed();
+ if (stream != null) {
+ log(stream.getStringBuilder(DEFAULT_CHARSET));
+ }
+ }
+
+ private class LoggingStream extends FilterOutputStream {
+
+ private final StringBuilder sb = new StringBuilder();
+ private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ LoggingStream(OutputStream out) {
+ super(out);
+ }
+
+ StringBuilder getStringBuilder(Charset charset) {
+ // write entity to the builder
+ final byte[] entity = baos.toByteArray();
+
+ sb.append(new String(entity, 0, entity.length, charset));
+ if (entity.length > maxEntitySize) {
+ sb.append("...more...");
+ }
+ sb.append('\n');
+
+ return sb;
+ }
+
+ @Override
+ public void write(final int i) throws IOException {
+ if (baos.size() <= maxEntitySize) {
+ baos.write(i);
+ }
+ out.write(i);
+ }
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecision.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecision.java
new file mode 100644
index 0000000000..e0ad170504
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecision.java
@@ -0,0 +1,38 @@
+
+package org.openecomp.mso.client.policy;
+
+
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "decision", "details" })
+public class PolicyDecision {
+
+ @JsonProperty("decision")
+ private String decision;
+ @JsonProperty("details")
+ private String details;
+
+ @JsonProperty("decision")
+ public String getDecision() {
+ return decision;
+ }
+
+ @JsonProperty("decision")
+ public void setDecision(String decision) {
+ this.decision = decision;
+ }
+
+ @JsonProperty("details")
+ public String getDetails() {
+ return details;
+ }
+
+ @JsonProperty("details")
+ public void setDetails(String details) {
+ this.details = details;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecisionRequest.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecisionRequest.java
new file mode 100644
index 0000000000..2af91f6638
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyDecisionRequest.java
@@ -0,0 +1,38 @@
+
+package org.openecomp.mso.client.policy;
+
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "decisionAttributes", "ecompcomponentName" })
+public class PolicyDecisionRequest {
+
+ @JsonProperty("decisionAttributes")
+ private DecisionAttributes decisionAttributes;
+ @JsonProperty("ecompcomponentName")
+ private String ecompcomponentName;
+
+ @JsonProperty("decisionAttributes")
+ public DecisionAttributes getDecisionAttributes() {
+ return decisionAttributes;
+ }
+
+ @JsonProperty("decisionAttributes")
+ public void setDecisionAttributes(DecisionAttributes decisionAttributes) {
+ this.decisionAttributes = decisionAttributes;
+ }
+
+ @JsonProperty("ecompcomponentName")
+ public String getEcompcomponentName() {
+ return ecompcomponentName;
+ }
+
+ @JsonProperty("ecompcomponentName")
+ public void setEcompcomponentName(String ecompcomponentName) {
+ this.ecompcomponentName = ecompcomponentName;
+ }
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyRestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyRestClient.java
new file mode 100644
index 0000000000..6af1c5dab7
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/PolicyRestClient.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * 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.openecomp.mso.client.policy;
+
+import java.util.Map;
+import java.util.UUID;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class PolicyRestClient extends RestClient {
+
+ private static final String ENDPOINT_KEY = "policy.endpoint";
+ private static final String X_ECOMP_REQUESTID = String.valueOf(UUID.randomUUID());
+
+ public PolicyRestClient() {
+ super(ENDPOINT_KEY);
+ }
+
+ @Override
+ protected void initializeHeaderMap(Map<String, String> headerMap) {
+ headerMap.put("ClientAuth", properties.get("policy.client.auth"));
+ headerMap.put("Authorization", properties.get("policy.auth"));
+ headerMap.put("Environment", properties.get("policy.environment"));
+ headerMap.put("X-ECOMP-RequestID", X_ECOMP_REQUESTID);
+ }
+
+ public PolicyDecision getDecision(String serviceType, String vnfType, String bbID, String workStep,
+ String errorCode) {
+ DecisionAttributes decisionAttributes = new DecisionAttributes();
+ decisionAttributes.setServiceType(serviceType);
+ decisionAttributes.setVNFType(vnfType);
+ decisionAttributes.setBBID(bbID);
+ decisionAttributes.setWorkStep(workStep);
+ decisionAttributes.setErrorCode(errorCode);
+
+ return this.getDecision(decisionAttributes);
+ }
+
+ private PolicyDecision getDecision(DecisionAttributes decisionAttributes) {
+ PolicyDecisionRequest decisionRequest = new PolicyDecisionRequest();
+ decisionRequest.setDecisionAttributes(decisionAttributes);
+ decisionRequest.setEcompcomponentName(ECOMP_COMPONENT_NAME);
+
+ return this.getBuilder().accept(MediaType.APPLICATION_JSON_TYPE)
+ .post(Entity.entity(decisionRequest, MediaType.APPLICATION_JSON)).readEntity(PolicyDecision.class);
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java
new file mode 100644
index 0000000000..f8e1ffd74f
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * 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.openecomp.mso.client.policy;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.logging.Logger;
+
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.WebTarget;
+
+
+import org.openecomp.mso.bpmn.core.PropertyConfiguration;
+import org.openecomp.mso.logger.MsoLogger;
+import org.springframework.stereotype.Service;
+
+@Service
+public abstract class RestClient {
+ protected static final String ECOMP_COMPONENT_NAME = "MSO";
+
+ private WebTarget webTarget;
+
+ protected final Map<String, String> headerMap;
+ protected final MsoLogger msoLogger;
+ protected Map<String, String> properties;
+ protected String host;
+
+ protected RestClient(String endpointKey) {
+ Logger logger = Logger.getLogger(getClass().getName());
+ msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
+
+ properties = PropertyConfiguration.getInstance().getProperties("mso.bpmn.urn.properties");
+ headerMap = new HashMap<>();
+ initializeHeaderMap(headerMap);
+
+ host = this.getHost(endpointKey);
+
+ webTarget = ClientBuilder.newClient().register(logger).register(new LoggingFilter())
+ .register(new CommonObjectMapperProvider()).target(host);
+ }
+
+ private String getHost(String key) {
+ return properties.get(key);
+ }
+
+ protected Builder getBuilder() {
+ Builder builder = webTarget.request();
+
+ for (Entry<String, String> entry : headerMap.entrySet()) {
+ builder.header(entry.getKey(), entry.getValue());
+ }
+ return builder;
+ }
+
+ protected abstract void initializeHeaderMap(Map<String, String> headerMap);
+}