From ac9387ceb0d2a4f1e1dd85be4e6d7818ab83363d Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Thu, 25 Apr 2019 11:31:45 +0000 Subject: Fixed issues found in integration testing Issue-ID: SO-1814 Change-Id: Ica6929e10cb40d535657eefc9786090af996ba32 Signed-off-by: MichaelMorris (cherry picked from commit df6508f90ffb0247b94a7357035e36af61b4f207) --- .../main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java index 8e6ebab43a..a627e82802 100644 --- a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java +++ b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java @@ -96,7 +96,7 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider { private Optional createOptional(final ResponseEntity response, final String url, final HttpMethod httpMethod) { - if (!response.getStatusCode().equals(HttpStatus.OK)) { + if (!response.getStatusCode().equals(HttpStatus.OK) && !response.getStatusCode().equals(HttpStatus.CREATED)) { final String message = "Unable to invoke HTTP " + httpMethod + " using URL: " + url + ", Response Code: " + response.getStatusCode(); LOGGER.error(message); -- cgit 1.2.3-korg From 3c32e98e85576724f7001dbeb27251552fa2161f Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Mon, 13 May 2019 14:12:13 -0700 Subject: Fix common ccsdk dependency and build Issue-ID: SO-1874 Change-Id: Ie151de0e2a0a0354a988e0d23deb77cd2a66a930 Signed-off-by: Marcus G K Williams --- common/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/pom.xml b/common/pom.xml index 0e9aa1d47c..2742afee1a 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -15,7 +15,7 @@ 1.17.1 3.6.1 4.1.30.Final - 0.4.2-SNAPSHOT + 0.4.2 -- cgit 1.2.3-korg From 65d71e97406a9a9b1c56475855f1d2e59adeec81 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Wed, 22 May 2019 11:08:32 -0400 Subject: HttpLookupUri is now serializable again cachedValue is now transient added custom serialization created serialization unit test for ServiceInstancesUri Change-Id: Idbc414a8483a4eae9c93ae8b06a1e77cbe683ca8 Issue-ID: SO-1906 Signed-off-by: Benjamin, Max (mb388a) --- .../so/client/aai/entities/uri/HttpLookupUri.java | 23 +++++++++-- .../aai/entities/uri/ServiceInstanceUriTest.java | 46 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java index f086a6abcf..37d21b375e 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java @@ -21,6 +21,8 @@ package org.onap.so.client.aai.entities.uri; import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.net.URI; import java.util.Map; import java.util.Optional; @@ -42,7 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri { - private Optional cachedValue = Optional.empty(); + private transient Optional cachedValue = Optional.empty(); private final AAIObjectType aaiType; protected HttpLookupUri(AAIObjectType type, Object... values) { @@ -78,8 +80,7 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri throw new GraphInventoryPayloadException("could not map payload: " + resultJson, e); } } - Optional cachedValueOpt = this.getCachedValue(); - return cachedValueOpt.isPresent() ? cachedValueOpt.get() : ""; + return cachedValue.get(); } protected Optional extractRelatedLink(String jsonString) throws IOException { @@ -139,6 +140,22 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri return new AAIResourcesClient(); } + private void writeObject(ObjectOutputStream oos) throws IOException { + + oos.writeUTF(this.cachedValue.orElse("")); + } + + private void readObject(ObjectInputStream ois) throws IOException { + + String value = ois.readUTF(); + if ("".equals(value)) { + this.cachedValue = Optional.empty(); + } else { + this.cachedValue = Optional.ofNullable(value); + } + + } + @Override public abstract URI buildNoNetwork(); } diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java index e829666577..9bef35e3b5 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java @@ -31,8 +31,14 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Files; @@ -50,9 +56,11 @@ import org.mockito.InjectMocks; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.client.aai.AAIClient; +import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; +import org.onap.so.client.graphinventory.entities.uri.Depth; import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException; import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException; import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException; @@ -227,4 +235,42 @@ public class ServiceInstanceUriTest { exception.expect(NotFoundException.class); spy.build(); } + + @Test + public void serializeTest() throws IOException, ClassNotFoundException, GraphInventoryUriNotFoundException, + GraphInventoryPayloadException { + ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + final String content = new String( + Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json"))); + + ServiceInstanceUri spy = spy(instance); + AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class); + AAIResultWrapper wrapper = mock(AAIResultWrapper.class); + when(mockResourcesClient.get(ArgumentMatchers.any(AAIResourceUri.class), + ArgumentMatchers.>any())).thenReturn(wrapper); + when(wrapper.getJson()).thenReturn(content); + when(spy.getResourcesClient()).thenReturn(mockResourcesClient); + spy.build(); + instance = spy.clone(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos); + objectOutputStream.writeObject(instance); + objectOutputStream.flush(); + objectOutputStream.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + + ObjectInputStream objectInputStream = new ObjectInputStream(bis); + ServiceInstanceUri e2 = (ServiceInstanceUri) objectInputStream.readObject(); + objectInputStream.close(); + + ServiceInstanceUri spy2 = spy(e2); + + assertEquals(spy2.build().toString(), instance.build().toString()); + + // use the cached value do not call out to external system + verify(spy2, times(0)).getResourcesClient(); + + } } -- cgit 1.2.3-korg From 4db782068934ebd20caa8405cd8644a2bf922934 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Tue, 28 May 2019 20:46:03 -0700 Subject: Fix UriBuilder import in OofUtils Import all changes from Casablanca that were incorrectly removed during merge from Casablanca back into master. Issue-ID: SO-1926 Change-Id: I8355e804586aa80e291f3c72a00bf69ce424316b Signed-off-by: Marcus G K Williams --- .../onap/so/bpmn/common/scripts/OofHoming.groovy | 36 ++++++++++++---------- .../onap/so/bpmn/common/scripts/OofUtils.groovy | 35 ++++++--------------- .../main/java/org/onap/so/utils/TargetEntity.java | 2 +- 3 files changed, 31 insertions(+), 42 deletions(-) (limited to 'common') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy index 623d5a67e3..6583ded413 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy @@ -32,17 +32,18 @@ import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.domain.Subscriber import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.DefaultProperties import org.onap.so.client.HttpClient import org.onap.so.client.HttpClientFactory -import org.slf4j.Logger -import org.slf4j.LoggerFactory +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.db.catalog.beans.AuthenticationType import org.onap.so.db.catalog.beans.CloudIdentity import org.onap.so.db.catalog.beans.CloudSite import org.onap.so.db.catalog.beans.HomingInstance import org.onap.so.db.catalog.beans.ServerType -import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.utils.TargetEntity +import org.slf4j.Logger +import org.slf4j.LoggerFactory import org.json.JSONArray import org.json.JSONObject @@ -108,12 +109,12 @@ class OofHoming extends AbstractServiceTaskProcessor { if (isBlank(subscriberInfo)) { subscriber = new Subscriber("", "", "") } else { - String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId") - String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName") - String subCommonSiteId = "" - if (jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")) { - subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId") - } + String subId = jsonUtil.getJsonValue(subscriberInfo, "globalSubscriberId") + String subName = jsonUtil.getJsonValue(subscriberInfo, "subscriberName") + String subCommonSiteId = "" + if (jsonUtil.jsonElementExist(subscriberInfo, "subscriberCommonSiteId")) { + subCommonSiteId = jsonUtil.getJsonValue(subscriberInfo, "subscriberCommonSiteId") + } subscriber = new Subscriber(subId, subName, subCommonSiteId) } @@ -163,21 +164,24 @@ class OofHoming extends AbstractServiceTaskProcessor { logger.debug( "Posting to OOF Url: " + urlString) - URL url = new URL(urlString); - HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.SNIRO) + URL url = new URL(urlString) + HttpClient httpClient = new HttpClientFactory().newJsonClient(url, TargetEntity.OOF) httpClient.addAdditionalHeader("Authorization", authHeader) - Response httpResponse = httpClient.post(oofRequest) + Response httpResponse = httpClient.post(oofRequest) - int responseCode = httpResponse.getStatus() - logger.debug("OOF sync response code is: " + responseCode) + int responseCode = httpResponse.getStatus() + logger.debug("OOF sync response code is: " + responseCode) + if(responseCode != 202){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.") + } logger.debug( "*** Completed Homing Call OOF ***") } } catch (BpmnError b) { throw b } catch (Exception e) { - logger.error(e); + logger.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in Homing callOof: " + e.getMessage()) } @@ -360,7 +364,7 @@ class OofHoming extends AbstractServiceTaskProcessor { throw b } catch (Exception e) { logger.debug( "ProcessHomingSolution Exception: " + e) - logger.error(e); + logger.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in Homing ProcessHomingSolution") } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index 2f46630715..4bfb29bc45 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -25,6 +25,7 @@ package org.onap.so.bpmn.common.scripts import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.util.OofInfraUtils import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.domain.HomingSolution import org.onap.so.bpmn.core.domain.ModelInfo @@ -53,6 +54,7 @@ import org.slf4j.LoggerFactory import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response +import javax.ws.rs.core.UriBuilder import javax.xml.ws.http.HTTPException import static org.onap.so.bpmn.common.scripts.GenericUtils.* @@ -62,6 +64,7 @@ class OofUtils { ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() + OofInfraUtils oofInfraUtils = new OofInfraUtils() private AbstractServiceTaskProcessor utils @@ -504,27 +507,8 @@ class OofUtils { * * @return void */ - Void createCloudSiteCatalogDb(CloudSite cloudSite, DelegateExecution execution) { - - String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution) - String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution) - String uri = "/cloudSite" - - URL url = new URL(endpoint + uri) - HttpClient client = new HttpClientFactory().newJsonClient(url, TargetEntity.EXTERNAL) - client.addAdditionalHeader(HttpHeaders.AUTHORIZATION, auth) - client.addAdditionalHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) - - Response response = client.post(request.getBody().toString()) - - int responseCode = response.getStatus() - logger.debug("CatalogDB response code is: " + responseCode) - String syncResponse = response.readEntity(String.class) - logger.debug("CatalogDB response is: " + syncResponse) - - if(responseCode != 202){ - exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CatalogDB.") - } + Void createCloudSite(CloudSite cloudSite, DelegateExecution execution) { + oofInfraUtils.createCloudSite(cloudSite, execution) } /** @@ -537,11 +521,12 @@ class OofUtils { Void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) { oofInfraUtils.createHomingInstance(homingInstance, execution) } - String getMsbHost(DelegateExecution execution) { - String msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap") - Integer msbPort = UrnPropertiesReader.getVariable("mso.msb.port", execution, "80").toInteger() + String getMsbHost(DelegateExecution execution) { + String msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap") + + Integer msbPort = UrnPropertiesReader.getVariable("mso.msb.port", execution, "80").toInteger() - return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString() + return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString() } } diff --git a/common/src/main/java/org/onap/so/utils/TargetEntity.java b/common/src/main/java/org/onap/so/utils/TargetEntity.java index 5f87378b79..ea0b70413b 100644 --- a/common/src/main/java/org/onap/so/utils/TargetEntity.java +++ b/common/src/main/java/org/onap/so/utils/TargetEntity.java @@ -23,7 +23,7 @@ package org.onap.so.utils; import java.util.EnumSet; public enum TargetEntity { - OPENSTACK_ADAPTER, BPMN, GRM, AAI, DMAAP, POLICY, CATALOG_DB, REQUEST_DB, VNF_ADAPTER, SDNC_ADAPTER, SNIRO, SDC, EXTERNAL, MULTICLOUD; + OPENSTACK_ADAPTER, BPMN, GRM, AAI, DMAAP, POLICY, CATALOG_DB, REQUEST_DB, VNF_ADAPTER, SDNC_ADAPTER, SNIRO, SDC, EXTERNAL, MULTICLOUD, OOF; private static final String PREFIX = "SO"; -- cgit 1.2.3-korg