diff options
Diffstat (limited to 'common/src/main/java/org/openecomp/mso/client/policy')
24 files changed, 1924 insertions, 0 deletions
diff --git a/common/src/main/java/org/openecomp/mso/client/policy/CommonObjectMapperProvider.java b/common/src/main/java/org/openecomp/mso/client/policy/CommonObjectMapperProvider.java new file mode 100644 index 0000000000..4f41b6441e --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/CommonObjectMapperProvider.java @@ -0,0 +1,49 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import javax.ws.rs.ext.ContextResolver; + +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; + +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); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + @Override + public ObjectMapper getContext(Class<?> type) { + return mapper; + } +}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/DecisionAttributes.java b/common/src/main/java/org/openecomp/mso/client/policy/DecisionAttributes.java new file mode 100644 index 0000000000..7b765ebb5f --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/DecisionAttributes.java @@ -0,0 +1,93 @@ +/*- + * ============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.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/common/src/main/java/org/openecomp/mso/client/policy/JettisonStyleMapperProvider.java b/common/src/main/java/org/openecomp/mso/client/policy/JettisonStyleMapperProvider.java new file mode 100644 index 0000000000..19579e810b --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/JettisonStyleMapperProvider.java @@ -0,0 +1,49 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import javax.ws.rs.ext.ContextResolver; + +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; + +public class JettisonStyleMapperProvider implements ContextResolver<ObjectMapper> { + + final ObjectMapper mapper; + + public JettisonStyleMapperProvider() { + + mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + mapper.enable(MapperFeature.USE_ANNOTATIONS); + mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true); + mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + @Override + public ObjectMapper getContext(Class<?> type) { + return mapper; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/LoggingFilter.java b/common/src/main/java/org/openecomp/mso/client/policy/LoggingFilter.java new file mode 100644 index 0000000000..b04069697e --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/LoggingFilter.java @@ -0,0 +1,157 @@ +/*- + * ============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.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 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.Provider; +import javax.ws.rs.ext.WriterInterceptor; +import javax.ws.rs.ext.WriterInterceptorContext; + +import org.openecomp.mso.logger.MsoLogger; + + +@Provider +@Priority(0) +public class LoggingFilter implements ClientRequestFilter, ClientResponseFilter, WriterInterceptor { + + private static final MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL); + private static final String ENTITY_STREAM_PROPERTY = "LoggingFilter.entityStream"; + private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + private final int maxEntitySize; + + public LoggingFilter() { + maxEntitySize = 1024 * 1024; + } + + public LoggingFilter(int maxPayloadSize) { + this.maxEntitySize = Integer.min(maxPayloadSize, 1024 * 1024); + } + + private void log(StringBuilder sb) { + logger.debug(sb.toString()); + } + + protected 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); + if (entitySize != -1) { + 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); + } + String method = formatMethod(requestContext); + log(new StringBuilder("Making " + method + " request to: " + requestContext.getUri() + "\nRequest Headers: " + requestContext.getHeaders().toString())); + + } + + @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)); + String method = formatMethod(requestContext); + log(sb.insert(0, "Response from " + method + ": " + requestContext.getUri() + "\nResponse Headers: " + responseContext.getHeaders().toString())); + } + } + + @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); + } + } + + private String formatMethod(ClientRequestContext requestContext) { + String method = requestContext.getHeaderString("X-HTTP-Method-Override"); + if (method == null) { + method = requestContext.getMethod(); + } else { + method = requestContext.getMethod() + " (overridden to " + method + ")"; + } + + return method; + } +}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/PolicyClient.java b/common/src/main/java/org/openecomp/mso/client/policy/PolicyClient.java new file mode 100644 index 0000000000..defd11bc99 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/PolicyClient.java @@ -0,0 +1,33 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import org.openecomp.mso.client.policy.entities.AllowedTreatments; +import org.openecomp.mso.client.policy.entities.DictionaryData; +import org.openecomp.mso.client.policy.entities.PolicyDecision; + +public interface PolicyClient { + + public PolicyDecision getDecision(String serviceType, String vnfType, String bbID, String workStep, + String errorCode); + + public DictionaryData getAllowedTreatments(String bbID, String workStep); +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/PolicyClientImpl.java b/common/src/main/java/org/openecomp/mso/client/policy/PolicyClientImpl.java new file mode 100644 index 0000000000..dc24b7ce16 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/PolicyClientImpl.java @@ -0,0 +1,94 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import org.openecomp.mso.client.RestPropertiesLoader; +import org.openecomp.mso.client.defaultproperties.PolicyRestPropertiesImpl; +import org.openecomp.mso.client.policy.entities.AllowedTreatments; +import org.openecomp.mso.client.policy.entities.Bbid; +import org.openecomp.mso.client.policy.entities.DecisionAttributes; +import org.openecomp.mso.client.policy.entities.DictionaryData; +import org.openecomp.mso.client.policy.entities.DictionaryItemsRequest; +import org.openecomp.mso.client.policy.entities.DictionaryJson; +import org.openecomp.mso.client.policy.entities.PolicyDecision; +import org.openecomp.mso.client.policy.entities.PolicyDecisionRequest; +import org.openecomp.mso.client.policy.entities.PolicyServiceType; +import org.openecomp.mso.client.policy.entities.Workstep; + +import java.util.List; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class PolicyClientImpl implements PolicyClient { + + protected final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); + private PolicyRestProperties props; + public PolicyClientImpl() { + props = RestPropertiesLoader.getInstance().getNewImpl(PolicyRestProperties.class); + if (props == null) { + metricsLogger.error("No RestProperty.PolicyRestProperties implementation found on classpath"); + props = new PolicyRestPropertiesImpl(); + } + } + 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) { + PolicyRestClient client = new PolicyRestClient(this.props, PolicyServiceType.GET_DECISION); + PolicyDecisionRequest decisionRequest = new PolicyDecisionRequest(); + decisionRequest.setDecisionAttributes(decisionAttributes); + decisionRequest.setEcompcomponentName(RestClient.ECOMP_COMPONENT_NAME); + + return client.post(decisionRequest, PolicyDecision.class); + } + + public DictionaryData getAllowedTreatments(String bbID, String workStep) + { + PolicyRestClient client = new PolicyRestClient(this.props, PolicyServiceType.GET_DICTIONARY_ITEMS); + DictionaryItemsRequest dictionaryItemsRequest = new DictionaryItemsRequest(); + dictionaryItemsRequest.setDictionaryType("Decision"); + dictionaryItemsRequest.setDictionary("RainyDayTreatments"); + final AllowedTreatments response = client.post(dictionaryItemsRequest, AllowedTreatments.class); + final DictionaryJson dictionaryJson = response.getDictionaryJson(); + final List<DictionaryData> dictionaryDataList = dictionaryJson.getDictionaryDatas(); + for(DictionaryData dictData : dictionaryDataList){ + Bbid bBid = dictData.getBbid(); + Workstep workstep = dictData.getWorkstep(); + String bBidString = bBid.getString(); + String workstepString = workstep.getString(); + if(bbID.equals(bBidString) && workStep.equals(workstepString)){ + return dictData; + } + } + metricsLogger.error("There is no AllowedTreatments with that specified parameter set"); + return null; + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/PolicyDecision.java b/common/src/main/java/org/openecomp/mso/client/policy/PolicyDecision.java new file mode 100644 index 0000000000..98c7e1558d --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/PolicyDecision.java @@ -0,0 +1,57 @@ +/*- + * ============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.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/common/src/main/java/org/openecomp/mso/client/policy/PolicyDecisionRequest.java b/common/src/main/java/org/openecomp/mso/client/policy/PolicyDecisionRequest.java new file mode 100644 index 0000000000..c83fb19e34 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/PolicyDecisionRequest.java @@ -0,0 +1,57 @@ +/*- + * ============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.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/common/src/main/java/org/openecomp/mso/client/policy/PolicyRestClient.java b/common/src/main/java/org/openecomp/mso/client/policy/PolicyRestClient.java new file mode 100644 index 0000000000..77fec34de6 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/PolicyRestClient.java @@ -0,0 +1,66 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import java.net.MalformedURLException; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +import javax.ws.rs.client.ClientResponseFilter; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriBuilderException; + +import org.openecomp.mso.client.ResponseExceptionMapperImpl; +import org.openecomp.mso.client.RestProperties; +import org.openecomp.mso.client.policy.entities.PolicyServiceType; +import org.springframework.stereotype.Service; + +@Service +public class PolicyRestClient extends RestClient { + + private static final UUID X_ECOMP_REQUESTID = UUID.randomUUID(); + private final PolicyRestProperties properties; + public PolicyRestClient(PolicyRestProperties props, PolicyServiceType serviceType) { + super(props, UUID.randomUUID(), Optional.of(UriBuilder.fromPath(serviceType.toString()).build())); + this.properties = props; + this.getClient(); + } + + @Override + protected void initializeHeaderMap(Map<String, String> headerMap) { + headerMap.put("ClientAuth", properties.getClientAuth()); + headerMap.put("Authorization", properties.getAuth()); + headerMap.put("Environment", properties.getEnvironment()); + this.addRequestId(X_ECOMP_REQUESTID); + } + + @Override + protected Optional<ClientResponseFilter> addResponseFilter() { + return Optional.of(new ResponseExceptionMapperImpl()); + } + + @Override + public RestClient addRequestId(UUID requestId) { + this.headerMap.put("X-ECOMP-RequestID", requestId.toString()); + return this; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/PolicyRestProperties.java b/common/src/main/java/org/openecomp/mso/client/policy/PolicyRestProperties.java new file mode 100644 index 0000000000..d89bd54f66 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/PolicyRestProperties.java @@ -0,0 +1,35 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; + +import org.openecomp.mso.client.RestProperties; + +public interface PolicyRestProperties extends RestProperties { + + public String getClientAuth(); + public String getAuth(); + public String getEnvironment(); + +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java b/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java new file mode 100644 index 0000000000..4e6ffd1c6a --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java @@ -0,0 +1,227 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.UUID; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.ClientResponseFilter; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.ext.ContextResolver; + +import org.apache.log4j.Logger; +import org.openecomp.mso.client.RestProperties; +import org.openecomp.mso.logger.MsoLogger; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Service +public abstract class RestClient { + protected static final String ECOMP_COMPONENT_NAME = "MSO"; + + private static final int MAX_PAYLOAD_SIZE = 1024 * 1024; + private WebTarget webTarget; + + protected final Map<String, String> headerMap; + protected final MsoLogger msoLogger; + protected URL host; + protected Optional<URI> path; + protected Logger logger; + protected String accept; + protected String contentType; + protected UUID requestId; + + protected RestClient(RestProperties props, UUID requestId, Optional<URI> path) { + logger = Logger.getLogger(getClass().getName()); + msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); + this.requestId = requestId; + headerMap = new HashMap<>(); + try { + host = props.getEndpoint(); + } catch (MalformedURLException e) { + logger.error("url not valid", e); + throw new RuntimeException(e); + } + + this.path = path; + initializeClient(getClient()); + } + + protected RestClient(RestProperties props, UUID requestId, Optional<URI> path, String accept, String contentType) { + this(props, requestId, path); + this.accept = accept; + this.contentType = contentType; + this.requestId = requestId; + + } + + protected RestClient(URL host, UUID requestId, String contentType) { + headerMap = new HashMap<>(); + logger = Logger.getLogger(getClass().getName()); + msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); + this.path = Optional.empty(); + this.host = host; + this.contentType = contentType; + this.requestId = requestId; + initializeClient(getClient()); + } + + /** + * Override method to return false to disable logging. + * + * @return true - to enable logging, false otherwise + */ + protected boolean enableLogging() { + return true; + } + + /** + * Override method to return custom value for max payload size. + * + * @return Default value for MAX_PAYLOAD_SIZE = 1024 * 1024 + */ + protected int getMaxPayloadSize() + { + return MAX_PAYLOAD_SIZE; + } + + protected Builder getBuilder() { + + Builder builder = webTarget.request(); + initializeHeaderMap(headerMap); + + for (Entry<String, String> entry : headerMap.entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + return builder; + } + + protected abstract void initializeHeaderMap(Map<String, String> headerMap); + + protected abstract Optional<ClientResponseFilter> addResponseFilter(); + + public abstract RestClient addRequestId(UUID requestId); + + protected ContextResolver<ObjectMapper> getMapper() { + return new CommonObjectMapperProvider(); + } + + protected String getAccept() { + return accept; + } + + protected String getContentType() { + return contentType; + } + + protected String getMergeContentType() { + return "application/merge-patch+json"; + } + + protected Client getClient() { + return ClientBuilder.newBuilder().build(); + } + + protected UUID getRequestId() { + return this.requestId; + } + protected void initializeClient(Client client) { + if (this.enableLogging()) { + client.register(logger).register(new LoggingFilter(this.getMaxPayloadSize())); + } + client.register(this.getMapper()); + Optional<ClientResponseFilter> responseFilter = this.addResponseFilter(); + responseFilter.ifPresent(clientResponseFilter -> client.register(clientResponseFilter)); + webTarget = path.<WebTarget>map(uri -> client.target(UriBuilder.fromUri(host + uri.toString()))) + .orElseGet(() -> client.target(host.toString())); + this.accept = MediaType.APPLICATION_JSON; + this.contentType = MediaType.APPLICATION_JSON; + } + + public Response get() { + return this.getBuilder().accept(this.getAccept()).get(); + } + + public Response post(Object obj) { + return this.getBuilder().accept(this.getAccept()).post(Entity.entity(obj, this.getContentType())); + } + + public Response patch(Object obj) { + return this.getBuilder().header("X-HTTP-Method-Override", "PATCH").accept(this.getAccept()) + .post(Entity.entity(obj, this.getMergeContentType())); + } + + public Response put(Object obj) { + return this.getBuilder().accept(this.getAccept()).put(Entity.entity(obj, this.getContentType())); + } + + public Response delete() { + return this.getBuilder().accept(this.getAccept()).delete(); + } + + public Response delete(Object obj) { + return this.getBuilder().header("X-HTTP-Method-Override", "DELETE").accept(this.getAccept()) + .put(Entity.entity(obj, this.getContentType())); + } + + public <T> T get(Class<T> resultClass) { + return this.get().readEntity(resultClass); + } + + public <T> T get(GenericType<T> resultClass) { + return this.get().readEntity(resultClass); + } + + public <T> T post(Object obj, Class<T> resultClass) { + return this.post(obj).readEntity(resultClass); + } + + public <T> T patch(Object obj, Class<T> resultClass) { + return this.patch(obj).readEntity(resultClass); + } + + public <T> T put(Object obj, Class<T> resultClass) { + return this.put(obj).readEntity(resultClass); + } + + public <T> T delete(Class<T> resultClass) { + return this.delete().readEntity(resultClass); + } + + public <T> T delete(Object obj, Class<T> resultClass) { + return this.delete(obj).readEntity(resultClass); + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/RestClientSSL.java b/common/src/main/java/org/openecomp/mso/client/policy/RestClientSSL.java new file mode 100644 index 0000000000..921664588a --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/RestClientSSL.java @@ -0,0 +1,99 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import java.io.FileInputStream; +import java.net.URI; +import java.security.NoSuchAlgorithmException; +import java.security.KeyStore; +import java.util.Optional; +import java.util.UUID; + +import javax.net.ssl.SSLContext; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; + +import org.openecomp.mso.client.RestProperties; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; + +public abstract class RestClientSSL extends RestClient { + + public static final String SSL_KEY_STORE_KEY = "javax.net.ssl.keyStore"; + public static final String SSL_KEY_STORE_PASSWORD_KEY = "javax.net.ssl.keyStorePassword"; + public static final String MSO_LOAD_SSL_CLIENT_KEYSTORE_KEY = "mso.load.ssl.client.keystore"; + + + protected RestClientSSL(RestProperties props, UUID requestId, Optional<URI> path) { + super(props, requestId, path); + } + + protected RestClientSSL(RestProperties props, UUID requestId, Optional<URI> path, String accept, String contentType) { + super(props, requestId, path, accept, contentType); + } + + @Override + protected Client getClient() { + + Client client = null; + try { + String loadSSLKeyStore = System.getProperty(RestClientSSL.MSO_LOAD_SSL_CLIENT_KEYSTORE_KEY); + if(loadSSLKeyStore != null && loadSSLKeyStore.equalsIgnoreCase("true")) { + KeyStore ks = getKeyStore(); + if(ks != null) { + client = ClientBuilder.newBuilder().keyStore(ks, System.getProperty(RestClientSSL.SSL_KEY_STORE_PASSWORD_KEY)).build(); + this.msoLogger.debug("RestClientSSL not using default SSL context - setting keystore here."); + return client; + } + } + //Use default SSL context + client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()).build(); + this.msoLogger.debug("RestClientSSL using default SSL context!"); + } catch (NoSuchAlgorithmException e) { + this.msoLogger.error(MessageEnum.APIH_GENERAL_EXCEPTION, "AAI", "Client init", MsoLogger.ErrorCode.UnknownError, "could not create SSL client", e); + throw new RuntimeException(e); + } + return client; + } + + private KeyStore getKeyStore() { + KeyStore ks = null; + char[] password = System.getProperty(RestClientSSL.SSL_KEY_STORE_PASSWORD_KEY).toCharArray(); + FileInputStream fis = null; + try { + ks = KeyStore.getInstance(KeyStore.getDefaultType()); + fis = new FileInputStream(System.getProperty(RestClientSSL.SSL_KEY_STORE_KEY)); + ks.load(fis, password); + } + catch(Exception e) { + return null; + } + finally { + if (fis != null) { + try { + fis.close(); + } + catch(Exception e) {} + } + } + return ks; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/AllowedTreatments.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/AllowedTreatments.java new file mode 100644 index 0000000000..50db843416 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/AllowedTreatments.java @@ -0,0 +1,105 @@ +/*- + * ============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.openecomp.mso.client.policy.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ +"dictionaryJson", +"dictionaryData", +"responseCode", +"responseMessage" +}) +public class AllowedTreatments{ + +@JsonProperty("dictionaryJson") +private DictionaryJson dictionaryJson; +@JsonProperty("dictionaryData") +private Object dictionaryData; +@JsonProperty("responseCode") +private Integer responseCode; +@JsonProperty("responseMessage") +private String responseMessage; + +@JsonProperty("dictionaryJson") +public DictionaryJson getDictionaryJson() { +return dictionaryJson; + } + +@JsonProperty("dictionaryJson") +public void setDictionaryJson(DictionaryJson dictionaryJson) { +this.dictionaryJson = dictionaryJson; + } + +public AllowedTreatments withDictionaryJson(DictionaryJson dictionaryJson) { +this.dictionaryJson = dictionaryJson; +return this; + } + +@JsonProperty("dictionaryData") +public Object getDictionaryData() { +return dictionaryData; + } + +@JsonProperty("dictionaryData") +public void setDictionaryData(Object dictionaryData) { +this.dictionaryData = dictionaryData; + } + +public AllowedTreatments withDictionaryData(Object dictionaryData) { +this.dictionaryData = dictionaryData; +return this; + } + +@JsonProperty("responseCode") +public Integer getResponseCode() { +return responseCode; + } + +@JsonProperty("responseCode") +public void setResponseCode(Integer responseCode) { +this.responseCode = responseCode; + } + +public AllowedTreatments withResponseCode(Integer responseCode) { +this.responseCode = responseCode; +return this; + } + +@JsonProperty("responseMessage") +public String getResponseMessage() { +return responseMessage; + } + +@JsonProperty("responseMessage") +public void setResponseMessage(String responseMessage) { +this.responseMessage = responseMessage; + } + +public AllowedTreatments withResponseMessage(String responseMessage) { +this.responseMessage = responseMessage; +return this; + } + +}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/Bbid.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/Bbid.java new file mode 100644 index 0000000000..382b27a04b --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/Bbid.java @@ -0,0 +1,87 @@ +/*- + * ============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.openecomp.mso.client.policy.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({
+"valueType",
+"string",
+"chars"
+})
+public class Bbid {
+
+@JsonProperty("valueType")
+private String valueType;
+@JsonProperty("string")
+private String string;
+@JsonProperty("chars")
+private String chars;
+
+@JsonProperty("valueType")
+public String getValueType() {
+return valueType;
+ }
+
+@JsonProperty("valueType")
+public void setValueType(String valueType) {
+this.valueType = valueType;
+ }
+
+public Bbid withValueType(String valueType) {
+this.valueType = valueType;
+return this;
+ }
+
+@JsonProperty("string")
+public String getString() {
+return string;
+ }
+
+@JsonProperty("string")
+public void setString(String string) {
+this.string = string;
+ }
+
+public Bbid withString(String string) {
+this.string = string;
+return this;
+ }
+
+@JsonProperty("chars")
+public String getChars() {
+return chars;
+ }
+
+@JsonProperty("chars")
+public void setChars(String chars) {
+this.chars = chars;
+ }
+
+public Bbid withChars(String chars) {
+this.chars = chars;
+return this;
+ }
+
+}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/DecisionAttributes.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/DecisionAttributes.java new file mode 100644 index 0000000000..9f40639e68 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/DecisionAttributes.java @@ -0,0 +1,94 @@ +/*- + * ============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.openecomp.mso.client.policy.entities; + + + +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/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryData.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryData.java new file mode 100644 index 0000000000..1ecf3366c7 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryData.java @@ -0,0 +1,105 @@ +/*- + * ============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.openecomp.mso.client.policy.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({
+"id",
+"bbid",
+"workstep",
+"treatments"
+})
+public class DictionaryData {
+
+@JsonProperty("id")
+private Id id;
+@JsonProperty("bbid")
+private Bbid bbid;
+@JsonProperty("workstep")
+private Workstep workstep;
+@JsonProperty("treatments")
+private Treatments treatments;
+
+@JsonProperty("id")
+public Id getId() {
+return id;
+ }
+
+@JsonProperty("id")
+public void setId(Id id) {
+this.id = id;
+ }
+
+public DictionaryData withId(Id id) {
+this.id = id;
+return this;
+ }
+
+@JsonProperty("bbid")
+public Bbid getBbid() {
+return bbid;
+ }
+
+@JsonProperty("bbid")
+public void setBbid(Bbid bbid) {
+this.bbid = bbid;
+ }
+
+public DictionaryData withBbid(Bbid bbid) {
+this.bbid = bbid;
+return this;
+ }
+
+@JsonProperty("workstep")
+public Workstep getWorkstep() {
+return workstep;
+ }
+
+@JsonProperty("workstep")
+public void setWorkstep(Workstep workstep) {
+this.workstep = workstep;
+ }
+
+public DictionaryData withWorkstep(Workstep workstep) {
+this.workstep = workstep;
+return this;
+ }
+
+@JsonProperty("treatments")
+public Treatments getTreatments() {
+return treatments;
+ }
+
+@JsonProperty("treatments")
+public void setTreatments(Treatments treatments) {
+this.treatments = treatments;
+ }
+
+public DictionaryData withTreatments(Treatments treatments) {
+this.treatments = treatments;
+return this;
+ }
+
+}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryItemsRequest.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryItemsRequest.java new file mode 100644 index 0000000000..d37d0c6f13 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryItemsRequest.java @@ -0,0 +1,56 @@ +/*- + * ============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.openecomp.mso.client.policy.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "dictionaryType", "dictionary" }) +public class DictionaryItemsRequest { + + @JsonProperty("dictionary") + private String dictionary; + @JsonProperty("dictionaryType") + private String dictionaryType; + + @JsonProperty("dictionary") + public String getDictionary() { + return dictionary; + } + + @JsonProperty("dictionary") + public void setDictionary(String dictionary) { + this.dictionary = dictionary; + } + + @JsonProperty("dictionaryType") + public String getDictionaryType() { + return dictionaryType; + } + + @JsonProperty("dictionaryType") + public void setDictionaryType(String dictionaryType) { + this.dictionaryType = dictionaryType; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryJson.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryJson.java new file mode 100644 index 0000000000..b6a95ae12a --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/DictionaryJson.java @@ -0,0 +1,53 @@ +/*- + * ============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.openecomp.mso.client.policy.entities;
+
+import java.util.ArrayList;
+import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({
+"DictionaryDatas"
+})
+public class DictionaryJson {
+
+@JsonProperty("DictionaryDatas")
+private List<DictionaryData> dictionaryDatas = new ArrayList<DictionaryData>();
+
+@JsonProperty("DictionaryDatas")
+public List<DictionaryData> getDictionaryDatas() {
+return dictionaryDatas;
+ }
+
+@JsonProperty("DictionaryDatas")
+public void setDictionaryDatas(List<DictionaryData> dictionaryDatas) {
+this.dictionaryDatas = dictionaryDatas;
+ }
+
+public DictionaryJson withDictionaryDatas(List<DictionaryData> dictionaryDatas) {
+this.dictionaryDatas = dictionaryDatas;
+return this;
+ }
+
+}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/Id.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/Id.java new file mode 100644 index 0000000000..728381a60b --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/Id.java @@ -0,0 +1,69 @@ +/*- + * ============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.openecomp.mso.client.policy.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({
+"integral",
+"valueType"
+})
+public class Id {
+
+@JsonProperty("integral")
+private Boolean integral;
+@JsonProperty("valueType")
+private String valueType;
+
+@JsonProperty("integral")
+public Boolean getIntegral() {
+return integral;
+ }
+
+@JsonProperty("integral")
+public void setIntegral(Boolean integral) {
+this.integral = integral;
+ }
+
+public Id withIntegral(Boolean integral) {
+this.integral = integral;
+return this;
+ }
+
+@JsonProperty("valueType")
+public String getValueType() {
+return valueType;
+ }
+
+@JsonProperty("valueType")
+public void setValueType(String valueType) {
+this.valueType = valueType;
+ }
+
+public Id withValueType(String valueType) {
+this.valueType = valueType;
+return this;
+ }
+
+}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyDecision.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyDecision.java new file mode 100644 index 0000000000..fbc8e23151 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyDecision.java @@ -0,0 +1,58 @@ +/*- + * ============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.openecomp.mso.client.policy.entities; + + + +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/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyDecisionRequest.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyDecisionRequest.java new file mode 100644 index 0000000000..bc20b9c143 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyDecisionRequest.java @@ -0,0 +1,58 @@ +/*- + * ============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.openecomp.mso.client.policy.entities; + + +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/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java new file mode 100644 index 0000000000..01f6738947 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java @@ -0,0 +1,48 @@ +/*- + * ============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.openecomp.mso.client.policy.entities; + +public enum PolicyServiceType { + GET_CONFIG("getConfig"), + SEND_EVENT("sendEvent"), + PUSH_POLICY("pushPolicy"), + CREATE_POLICY("createPolicy"), + UPDATE_POLICY("updatePolicy"), + GET_DECISION("getDecision"), + GET_METRICS("getMetrics"), + DELETE_POLICY("deletePolicy"), + LIST_CONFIG("listConfig"), + CREATE_DICTIONARY_ITEM("createDictionaryItem"), + UPDATE_DICTIONARY_ITEM("updateDictionaryItem"), + GET_DICTIONARY_ITEMS("getDictionaryItems"); + + private final String name; + + PolicyServiceType(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + +} diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/Treatments.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/Treatments.java new file mode 100644 index 0000000000..13af8932aa --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/Treatments.java @@ -0,0 +1,87 @@ +/*- + * ============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.openecomp.mso.client.policy.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({
+"valueType",
+"string",
+"chars"
+})
+public class Treatments {
+
+@JsonProperty("valueType")
+private String valueType;
+@JsonProperty("string")
+private String string;
+@JsonProperty("chars")
+private String chars;
+
+@JsonProperty("valueType")
+public String getValueType() {
+return valueType;
+ }
+
+@JsonProperty("valueType")
+public void setValueType(String valueType) {
+this.valueType = valueType;
+ }
+
+public Treatments withValueType(String valueType) {
+this.valueType = valueType;
+return this;
+ }
+
+@JsonProperty("string")
+public String getString() {
+return string;
+ }
+
+@JsonProperty("string")
+public void setString(String string) {
+this.string = string;
+ }
+
+public Treatments withString(String string) {
+this.string = string;
+return this;
+ }
+
+@JsonProperty("chars")
+public String getChars() {
+return chars;
+ }
+
+@JsonProperty("chars")
+public void setChars(String chars) {
+this.chars = chars;
+ }
+
+public Treatments withChars(String chars) {
+this.chars = chars;
+return this;
+ }
+
+}
\ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/policy/entities/Workstep.java b/common/src/main/java/org/openecomp/mso/client/policy/entities/Workstep.java new file mode 100644 index 0000000000..9d2adfe2c0 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/policy/entities/Workstep.java @@ -0,0 +1,88 @@ +/*- + * ============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.openecomp.mso.client.policy.entities;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({
+"valueType",
+"string",
+"chars"
+})
+public class Workstep {
+
+@JsonProperty("valueType")
+private String valueType;
+@JsonProperty("string")
+private String string;
+@JsonProperty("chars")
+private String chars;
+
+@JsonProperty("valueType")
+public String getValueType() {
+return valueType;
+ }
+
+@JsonProperty("valueType")
+public void setValueType(String valueType) {
+this.valueType = valueType;
+ }
+
+public Workstep withValueType(String valueType) {
+this.valueType = valueType;
+return this;
+ }
+
+@JsonProperty("string")
+public String getString() {
+return string;
+ }
+
+@JsonProperty("string")
+public void setString(String string) {
+this.string = string;
+ }
+
+public Workstep withString(String string) {
+this.string = string;
+return this;
+ }
+
+@JsonProperty("chars")
+public String getChars() {
+return chars;
+ }
+
+@JsonProperty("chars")
+public void setChars(String chars) {
+this.chars = chars;
+ }
+
+public Workstep withChars(String chars) {
+this.chars = chars;
+return this;
+ }
+
+}
|