diff options
Diffstat (limited to 'common/src')
13 files changed, 263 insertions, 50 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java b/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java index ac6e939e9e..4f235c35f1 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java @@ -20,25 +20,17 @@ package org.onap.so.client.aai; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; - import java.net.URI; -import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.regex.Pattern; import javax.ws.rs.core.Response; import org.onap.so.client.ResponseExceptionMapper; import org.onap.so.client.RestClientSSL; -import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException; import org.onap.so.client.policy.CommonObjectMapperProvider; -import org.onap.so.jsonpath.JsonPathUtil; import org.onap.so.utils.TargetEntity; -import com.fasterxml.jackson.core.JsonProcessingException; - public class AAIRestClient extends RestClientSSL { private final AAIProperties aaiProperties; @@ -58,7 +50,7 @@ public class AAIRestClient extends RestClientSSL { @Override protected void initializeHeaderMap(Map<String, String> headerMap) { - headerMap.put("X-FromAppId", "MSO"); + headerMap.put("X-FromAppId", aaiProperties.getSystemName()); headerMap.put("X-TransactionId", requestId); String auth = aaiProperties.getAuth(); String key = aaiProperties.getKey(); diff --git a/common/src/main/java/org/onap/so/client/aai/AAIRestClientI.java b/common/src/main/java/org/onap/so/client/aai/AAIRestClientI.java index 785c82bb71..62d7d565ac 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIRestClientI.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIRestClientI.java @@ -31,11 +31,11 @@ public interface AAIRestClientI { List<Pserver> getPhysicalServerByVnfId(String vnfId) throws IOException; - void updateMaintenceFlagVnfId(String vnfId, boolean inMaint) throws Exception; + void updateMaintenceFlagVnfId(String vnfId, boolean inMaint); GenericVnf getVnfByName(String vnfId); - Optional<Pnf> getPnfByName(String pnfId, String transactionLoggingUuid) throws Exception; + Optional<Pnf> getPnfByName(String pnfId); - void createPnf(String pnfId, String transactionLoggingUuid, Pnf pnf) throws IOException; + void createPnf(String pnfId, Pnf pnf); } diff --git a/common/src/main/java/org/onap/so/client/aai/AAIRestClientImpl.java b/common/src/main/java/org/onap/so/client/aai/AAIRestClientImpl.java index 1c02409b56..b2c7fcc062 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIRestClientImpl.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIRestClientImpl.java @@ -80,7 +80,7 @@ public class AAIRestClientImpl implements AAIRestClientI { } @Override - public Optional<Pnf> getPnfByName(String pnfId, String transactionLoggingUuid) { + public Optional<Pnf> getPnfByName(String pnfId) { Response response = new AAIResourcesClient() .getFullResponse(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId)); if (response.getStatus() != 200) { @@ -91,7 +91,7 @@ public class AAIRestClientImpl implements AAIRestClientI { } @Override - public void createPnf(String pnfId, String transactionLoggingUuid, Pnf pnf) { + public void createPnf(String pnfId, Pnf pnf) { new AAIResourcesClient() .createIfNotExists(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId), Optional.of(pnf)); } diff --git a/common/src/main/java/org/onap/so/client/grm/beans/ServiceEndPointList.java b/common/src/main/java/org/onap/so/client/grm/beans/ServiceEndPointList.java index 19bbe69cf2..2b7a81d590 100644 --- a/common/src/main/java/org/onap/so/client/grm/beans/ServiceEndPointList.java +++ b/common/src/main/java/org/onap/so/client/grm/beans/ServiceEndPointList.java @@ -22,27 +22,21 @@ package org.onap.so.client.grm.beans; import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonPropertyOrder({ "serviceEndPointList" }) +//@JsonIgnoreProperties(ignoreUnknown = true) public class ServiceEndPointList { - @JsonProperty("serviceEndPointList") + @JsonAlias("ServiceEndPointList") private List<ServiceEndPoint> serviceEndPointList = null; - @JsonProperty("serviceEndPointList") public List<ServiceEndPoint> getServiceEndPointList() { return serviceEndPointList; } - @JsonProperty("serviceEndPointList") public void setServiceEndPointList(List<ServiceEndPoint> serviceEndPointList) { this.serviceEndPointList = serviceEndPointList; } - } diff --git a/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java b/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java index 5951928bf4..882a390c7b 100644 --- a/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java +++ b/common/src/main/java/org/onap/so/client/sdno/SDNOValidatorImpl.java @@ -77,17 +77,17 @@ public class SDNOValidatorImpl implements SDNOValidator { protected SDNO buildRequestDiagnostic(GenericVnf vnf, UUID uuid, String requestingUserId) { - Optional<String> vnfType; - if (vnf.getVnfType() == null) { - vnfType = Optional.empty(); + Optional<String> nfRole; + if (vnf.getNfRole() == null) { + nfRole = Optional.empty(); } else { - vnfType = Optional.of(vnf.getVnfType()); + nfRole = Optional.of(vnf.getNfRole()); } Input input = new Input(); SDNO parentRequest = new SDNO(); Body body = new Body(); parentRequest.setBody(body); - parentRequest.setNodeType(vnfType.orElse("NONE").toUpperCase()); + parentRequest.setNodeType(nfRole.orElse("NONE").toUpperCase()); parentRequest.setOperation("health-diagnostic"); body.setInput(input); @@ -97,6 +97,7 @@ public class SDNOValidatorImpl implements SDNOValidator { request.setRequestClientName(clientName); request.setRequestNodeName(vnf.getVnfName()); request.setRequestNodeUuid(vnf.getVnfId()); + request.setRequestNodeType(nfRole.orElse("NONE").toUpperCase()); request.setRequestNodeIp(vnf.getIpv4OamAddress()); //generic-vnf oam ip request.setRequestUserId(requestingUserId); //mech id? request.setRequestId(uuid.toString()); //something to identify this request by for polling diff --git a/common/src/main/java/org/onap/so/exceptions/ValidationException.java b/common/src/main/java/org/onap/so/exceptions/ValidationException.java index 713fac70f3..b91c30c598 100644 --- a/common/src/main/java/org/onap/so/exceptions/ValidationException.java +++ b/common/src/main/java/org/onap/so/exceptions/ValidationException.java @@ -32,9 +32,9 @@ public class ValidationException extends Exception { private static final long serialVersionUID = 1L; private static final String VALIDATION_FAIL = "No valid $ELEMENT is specified"; - private static final String INVALID_ELEMENT = "$ELEMENT is not valid in the $VERSION version"; + private static final String UNMATCHED_ELEMENTS = "$ELEMENT does not match $SECOND_ELEMENT"; private static final String REPLACE_ELEMENT_KEY = "\\$ELEMENT"; - private static final String REPLACE_VERSION_KEY = "\\$VERSION"; + private static final String REPLACE_SECOND_ELEMENT_KEY = "\\$SECOND_ELEMENT"; @Deprecated public ValidationException (String msg) { @@ -48,7 +48,7 @@ public class ValidationException extends Exception { public ValidationException (String msg, Exception cause) { super (VALIDATION_FAIL.replaceAll (REPLACE_ELEMENT_KEY, msg), cause); } - public ValidationException(String msg, String version) { - super(INVALID_ELEMENT.replaceAll(REPLACE_ELEMENT_KEY, msg).replaceAll(REPLACE_VERSION_KEY, version)); + public ValidationException(String firstElement, String secondElement) { + super(UNMATCHED_ELEMENTS.replaceAll(REPLACE_ELEMENT_KEY, firstElement).replaceAll(REPLACE_SECOND_ELEMENT_KEY, secondElement)); } -} +}
\ No newline at end of file diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java b/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java index 8e7e5e945e..d39efddf43 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java @@ -22,6 +22,8 @@ package org.onap.so.serviceinstancebeans; import java.util.List; +import org.apache.commons.lang3.builder.ToStringBuilder; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -31,6 +33,7 @@ public class Request { protected String requestId; protected String startTime; + protected String finishTime; protected String requestScope; protected String requestType; protected RequestDetails requestDetails; @@ -51,6 +54,12 @@ public class Request { public void setStartTime(String startTime) { this.startTime = startTime; } + public String getFinishTime() { + return finishTime; + } + public void setFinishTime(String finishTime) { + this.finishTime = finishTime; + } public String getRequestScope() { return requestScope; } @@ -89,11 +98,9 @@ public class Request { } @Override public String toString() { - return "Request [requestId=" + requestId + ", startTime=" + startTime - + ", requestScope=" + requestScope + ", requestType=" + requestType - + ", requestDetails=" + requestDetails + ", instanceReferences=" + instanceReferences - + ", requestStatus=" + requestStatus + ", requestProcessingData=" + requestProcessingData + "]"; + return new ToStringBuilder(this).append("requestId", requestId).append("startTime", startTime) + .append("finishTime", finishTime).append("requestScope", requestScope).append("requestType", requestType) + .append("requestDetails", requestDetails).append("instanceReferences", instanceReferences) + .append("requestStatus", requestStatus).append("requestProcessingData", requestProcessingData).toString(); } - - } diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java index 8adce38ada..4c3597b2c1 100644 --- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java +++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestStatus.java @@ -30,7 +30,6 @@ public class RequestStatus { protected String requestState; protected String statusMessage; protected Integer percentProgress; - protected String finishTime; protected String timeStamp; @@ -52,12 +51,6 @@ public class RequestStatus { public void setPercentProgress(Integer percentProgress) { this.percentProgress = percentProgress; } - public String getFinishTime() { - return finishTime; - } - public void setFinishTime(String finishTime) { - this.finishTime = finishTime; - } public String getTimeStamp() { return timeStamp; } @@ -67,6 +60,6 @@ public class RequestStatus { @Override public String toString() { return new ToStringBuilder(this).append("requestState", requestState).append("statusMessage", statusMessage) - .append("percentProgress", percentProgress).append("finishTime", finishTime).append("timeStamp", timeStamp).toString(); + .append("percentProgress", percentProgress).append("timeStamp", timeStamp).toString(); } } diff --git a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java index a1fb43ea5e..d0d0e6701b 100644 --- a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java +++ b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java @@ -58,6 +58,30 @@ public class ServiceEndPointListTest { assertEquals("DEV", se.getProperties().get(0).getValue()); } + @Test + public void testUnmarshallServiceEndpointListStartsWithUppercase() throws Exception { + String endpointsJson = getFileContentsAsString("__files/grm/endpoints2.json"); + ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class); + + List<ServiceEndPoint> list = sel.getServiceEndPointList(); + ServiceEndPoint se = list.get(0); + + assertEquals(3, list.size()); + assertEquals("dummy.pod.ns.dummy-pod3", se.getName()); + assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor())); + assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor())); + assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch())); + assertEquals("192.168.120.218", se.getHostAddress()); + assertEquals("32004", se.getListenPort()); + assertEquals("37.7022", se.getLatitude()); + assertEquals("121.9358", se.getLongitude()); + assertEquals("/", se.getContextPath()); + assertEquals("edge", se.getOperationalInfo().getCreatedBy()); + assertEquals("edge", se.getOperationalInfo().getUpdatedBy()); + assertEquals("Environment", se.getProperties().get(0).getName()); + assertEquals("DEV", se.getProperties().get(0).getValue()); + } + protected String getFileContentsAsString(String fileName) { String content = ""; diff --git a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java new file mode 100644 index 0000000000..79ce196bd3 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.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.onap.so.client.sdno; + +import static org.junit.Assert.assertEquals; +import java.util.UUID; + +import org.junit.Test; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.client.sdno.beans.RequestHealthDiagnostic; +import org.onap.so.client.sdno.beans.SDNO; + +public class SDNOValidatorImplTest { + + @Test + public void buildRequestDiagnosticTest() throws Exception { + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + UUID uuid = UUID.randomUUID(); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfName("VNFNAME"); + vnf.setVnfId("test"); + vnf.setIpv4OamAddress("1.2.3.4"); + vnf.setNfRole("VPE"); + SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); + assertEquals(request.getNodeType(), "VPE"); + assertEquals(request.getOperation(), "health-diagnostic"); + + RequestHealthDiagnostic innerRequest = request.getBody().getInput().getRequestHealthDiagnostic(); + assertEquals(innerRequest.getRequestClientName(), "MSO"); + assertEquals(innerRequest.getRequestNodeName(), "VNFNAME"); + assertEquals(innerRequest.getRequestNodeUuid(), "test"); + assertEquals(innerRequest.getRequestNodeType(), "VPE"); + assertEquals(innerRequest.getRequestNodeIp(), "1.2.3.4"); + assertEquals(innerRequest.getRequestUserId(), "mechid"); + assertEquals(innerRequest.getRequestId(), uuid.toString()); + assertEquals(innerRequest.getHealthDiagnosticCode(), "default"); + + } +} diff --git a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java index d66f5f64f7..9794c9b622 100644 --- a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java +++ b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java @@ -100,7 +100,7 @@ public class SDNOValidatorTest { GenericVnf vnf = new GenericVnf(); vnf.setVnfId("test"); vnf.setIpv4OamAddress("1.2.3.4"); - vnf.setVnfType("VPE"); + vnf.setNfRole("VPE"); SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(request); diff --git a/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java b/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java index b3ae7ba9f5..27fb584b3b 100644 --- a/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java +++ b/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java @@ -47,7 +47,7 @@ public class ValidationExceptionTest { @Test public void validationExceptionVersion(){ - ValidationException e = new ValidationException("testMessage", "1.0"); - Assert.assertEquals("testMessage is not valid in the 1.0 version", e.getMessage()); + ValidationException e = new ValidationException("testMessage", "secondTestMessage"); + Assert.assertEquals("testMessage does not match secondTestMessage", e.getMessage()); } } diff --git a/common/src/test/resources/__files/grm/endpoints2.json b/common/src/test/resources/__files/grm/endpoints2.json new file mode 100644 index 0000000000..7c9816ff55 --- /dev/null +++ b/common/src/test/resources/__files/grm/endpoints2.json @@ -0,0 +1,145 @@ +{ + "ServiceEndPointList": [ + { + "name": "dummy.pod.ns.dummy-pod3", + "version": { + "major": 1, + "minor": 0, + "patch": "0" + }, + "hostAddress": "192.168.120.218", + "listenPort": "32004", + "latitude": "37.7022", + "longitude": "121.9358", + "registrationTime": "2017-07-18T15:39:17.367+0000", + "expirationTime": "9999-10-09T15:39:17.368+0000", + "contextPath": "/", + "routeOffer": "DEFAULT", + "statusInfo": { + "status": "RUNNING" + }, + "eventStatusInfo": { + "status": "RUNNING" + }, + "validatorStatusInfo": { + "status": "RUNNING" + }, + "operationalInfo": { + "createdBy": "edge", + "updatedBy": "edge", + "createdTimestamp": "2017-07-18T15:39:17.367+0000", + "updatedTimestamp": "2017-07-18T15:39:17.367+0000" + }, + "protocol": "dummypod-port", + "properties": [ + { + "name": "Environment", + "value": "DEV" + }, + { + "name": "Kubernetes Namespace", + "value": "dummy-pod-ns" + }, + { + "name": "cpfrun_cluster_name", + "value": "CI-PDK1-TFINIT-CJ9125401" + } + ], + "disableType": [] + }, + { + "name": "dummy.pod.ns.dummy-pod3", + "version": { + "major": 1, + "minor": 0, + "patch": "0" + }, + "hostAddress": "192.168.120.22", + "listenPort": "32004", + "latitude": "1.0", + "longitude": "1.0", + "registrationTime": "2017-07-18T15:39:17.816+0000", + "expirationTime": "9999-10-09T15:39:17.817+0000", + "contextPath": "/", + "routeOffer": "DEFAULT", + "statusInfo": { + "status": "RUNNING" + }, + "eventStatusInfo": { + "status": "RUNNING" + }, + "validatorStatusInfo": { + "status": "RUNNING" + }, + "operationalInfo": { + "createdBy": "edge", + "updatedBy": "edge", + "createdTimestamp": "2017-07-18T15:39:17.816+0000", + "updatedTimestamp": "2017-07-18T15:39:17.816+0000" + }, + "protocol": "dummypod-port", + "properties": [ + { + "name": "Environment", + "value": "DEV" + }, + { + "name": "Kubernetes Namespace", + "value": "dummy-pod-ns" + }, + { + "name": "cpfrun_cluster_name", + "value": "CI-PDK1-TFINIT-CJ9125401" + } + ], + "disableType": [] + }, + { + "name": "dummy.pod.ns.dummy-pod1", + "version": { + "major": 1, + "minor": 0, + "patch": "0" + }, + "hostAddress": "192.168.120.218", + "listenPort": "32002", + "latitude": "1.0", + "longitude": "1.0", + "registrationTime": "2017-07-18T15:39:14.443+0000", + "expirationTime": "9999-10-09T15:39:14.453+0000", + "contextPath": "/", + "routeOffer": "DEFAULT", + "statusInfo": { + "status": "RUNNING" + }, + "eventStatusInfo": { + "status": "RUNNING" + }, + "validatorStatusInfo": { + "status": "RUNNING" + }, + "operationalInfo": { + "createdBy": "edge", + "updatedBy": "edge", + "createdTimestamp": "2017-07-18T15:39:14.443+0000", + "updatedTimestamp": "2017-07-18T15:39:14.443+0000" + }, + "protocol": "dummypod-port", + "properties": [ + { + "name": "Environment", + "value": "DEV" + }, + { + "name": "Kubernetes Namespace", + "value": "dummy-pod-ns" + }, + { + "name": "cpfrun_cluster_name", + "value": "CI-PDK1-TFINIT-CJ9125401" + } + ], + "disableType": [] + } + ] +}
\ No newline at end of file |