diff options
Diffstat (limited to 'models-interactions')
12 files changed, 158 insertions, 138 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java index 8aac67bb0..45fbbca65 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java @@ -19,6 +19,8 @@ package org.onap.policy.controlloop.actor.cds.beans; import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; import java.util.Map; import lombok.Getter; import lombok.Setter; @@ -30,7 +32,8 @@ import org.slf4j.LoggerFactory; @Getter @Setter -public class CdsActionRequest { +public class CdsActionRequest implements Serializable { + private static final long serialVersionUID = -4172157702597791493L; private static final Logger LOGGER = LoggerFactory.getLogger(CdsActionRequest.class); private static final Coder CODER = new StandardCoder(); diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java index b79aca061..9adb69232 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java @@ -19,7 +19,6 @@ package org.onap.policy.controlloop.actor.cds.constants; public class CdsActorConstants { - public static final String CDS_ACTOR = "CDS"; // CDS Status @@ -36,4 +35,8 @@ public class CdsActorConstants { public static final String ORIGINATOR_ID = "POLICY"; // Temporarily set to synchronous mode to support current rules, since callbacks aren't supported yet public static final String CDS_MODE = "sync"; + + private CdsActorConstants() { + // Hide implicit public constructor + } } diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java index 28a1676ed..eb82ae231 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java @@ -87,6 +87,8 @@ public class CdsActorServiceProviderTest { // Setup policy policy = new Policy(); Map<String, String> payloadMap = new HashMap<String, String>() { + private static final long serialVersionUID = 1L; + { put(CdsActorConstants.KEY_CBA_NAME, CDS_BLUEPRINT_NAME); put(CdsActorConstants.KEY_CBA_VERSION, CDS_BLUEPRINT_VERSION); @@ -124,7 +126,7 @@ public class CdsActorServiceProviderTest { @Test public void testActor() { - assertEquals(cdsActor.actor(), CdsActorConstants.CDS_ACTOR); + assertEquals(CdsActorConstants.CDS_ACTOR, cdsActor.actor()); } @Test @@ -147,7 +149,7 @@ public class CdsActorServiceProviderTest { assertTrue(cdsRequest.hasCommonHeader()); CommonHeader commonHeader = cdsRequest.getCommonHeader(); assertEquals(commonHeader.getRequestId(), REQUEST_ID.toString()); - assertEquals(commonHeader.getSubRequestId(), SUBREQUEST_ID); + assertEquals(SUBREQUEST_ID, commonHeader.getSubRequestId()); assertTrue(cdsRequest.hasPayload()); Struct cdsPayload = cdsRequest.getPayload(); @@ -155,24 +157,24 @@ public class CdsActorServiceProviderTest { assertTrue(cdsRequest.hasActionIdentifiers()); ActionIdentifiers actionIdentifiers = cdsRequest.getActionIdentifiers(); - assertEquals(actionIdentifiers.getActionName(), CDS_RECIPE); - assertEquals(actionIdentifiers.getBlueprintName(), CDS_BLUEPRINT_NAME); - assertEquals(actionIdentifiers.getBlueprintVersion(), CDS_BLUEPRINT_VERSION); + assertEquals(CDS_RECIPE, actionIdentifiers.getActionName()); + assertEquals(CDS_BLUEPRINT_NAME, actionIdentifiers.getBlueprintName()); + assertEquals(CDS_BLUEPRINT_VERSION, actionIdentifiers.getBlueprintVersion()); } @Test public void testRecipePayloads() { - assertEquals(cdsActor.recipePayloads("").size(), 0); + assertEquals(0, cdsActor.recipePayloads("").size()); } @Test public void testRecipes() { - assertEquals(cdsActor.recipes().size(), 0); + assertEquals(0, cdsActor.recipes().size()); } @Test public void testRecipeTargets() { - assertEquals(cdsActor.recipeTargets("").size(), 0); + assertEquals(0, cdsActor.recipeTargets("").size()); } @Test diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java index 8aad5feb3..842d0f6a5 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java @@ -207,6 +207,7 @@ public class SoActorServiceProvider implements Actor { soModelInfo.setModelName(policy.getTarget().getModelName()); soModelInfo.setModelVersion(policy.getTarget().getModelVersion()); soModelInfo.setModelVersionId(policy.getTarget().getModelVersionId()); + soModelInfo.setModelType("vfModule"); return soModelInfo; } diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java index ca0c1867f..7024231e3 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java @@ -62,12 +62,17 @@ public class AaiCqResponse { properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false); // Define JAXB context try { - jaxbContext = - JAXBContextFactory - .createContext( - new Class[] {Vserver.class, GenericVnf.class, VfModule.class, - CloudRegion.class, ServiceInstance.class, Tenant.class, ModelVer.class}, - properties); + // @formatter:off + jaxbContext = JAXBContextFactory.createContext(new Class[] { + Vserver.class, + GenericVnf.class, + VfModule.class, + CloudRegion.class, + ServiceInstance.class, + Tenant.class, + ModelVer.class + }, properties); + // @formatter:on unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { LOGGER.error("Could not initialize JAXBContext", e); @@ -81,8 +86,7 @@ public class AaiCqResponse { /** * Constructor creates a custom query response from a valid json string. * - * @param jsonString - * A&AI Custom Query response JSON string + * @param jsonString A&AI Custom Query response JSON string */ public AaiCqResponse(String jsonString) { @@ -98,8 +102,8 @@ public class AaiCqResponse { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource(new StringReader( - resultsArray.getJSONObject(i).getJSONObject("vserver").toString())); + StreamSource json = new StreamSource( + new StringReader(resultsArray.getJSONObject(i).getJSONObject("vserver").toString())); // Getting the vserver pojo again from the json Vserver vserver = this.getAaiObject(json, Vserver.class); @@ -110,8 +114,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has(GENERIC_VNF)) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource(new StringReader( - resultsArray.getJSONObject(i).getJSONObject(GENERIC_VNF).toString())); + StreamSource json = new StreamSource( + new StringReader(resultsArray.getJSONObject(i).getJSONObject(GENERIC_VNF).toString())); // Getting the generic vnf pojo again from the json GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class); @@ -124,8 +128,8 @@ public class AaiCqResponse { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource(new StringReader( - resultsArray.getJSONObject(i).getJSONObject("service-instance").toString())); + StreamSource json = new StreamSource( + new StringReader(resultsArray.getJSONObject(i).getJSONObject("service-instance").toString())); // Getting the employee pojo again from the json ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class); @@ -137,8 +141,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has(VF_MODULE)) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource(new StringReader( - resultsArray.getJSONObject(i).getJSONObject(VF_MODULE).toString())); + StreamSource json = new StreamSource( + new StringReader(resultsArray.getJSONObject(i).getJSONObject(VF_MODULE).toString())); // Getting the vf module pojo again from the json VfModule vfModule = this.getAaiObject(json, VfModule.class); @@ -150,8 +154,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has("cloud-region")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource(new StringReader( - resultsArray.getJSONObject(i).getJSONObject("cloud-region").toString())); + StreamSource json = new StreamSource( + new StringReader(resultsArray.getJSONObject(i).getJSONObject("cloud-region").toString())); // Getting the cloud region pojo again from the json CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class); @@ -163,8 +167,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has("tenant")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource(new StringReader( - resultsArray.getJSONObject(i).getJSONObject("tenant").toString())); + StreamSource json = new StreamSource( + new StringReader(resultsArray.getJSONObject(i).getJSONObject("tenant").toString())); // Getting the tenant pojo again from the json Tenant tenant = this.getAaiObject(json, Tenant.class); @@ -176,8 +180,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has("model-ver")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource(new StringReader( - resultsArray.getJSONObject(i).getJSONObject("model-ver").toString())); + StreamSource json = new StreamSource( + new StringReader(resultsArray.getJSONObject(i).getJSONObject("model-ver").toString())); // Getting the ModelVer pojo again from the json ModelVer modelVer = this.getAaiObject(json, ModelVer.class); @@ -209,8 +213,7 @@ public class AaiCqResponse { /** * Get list of A&AI objects in the custom query. * - * @param classOfResponse - * Class of the type of A&AI objects to be returned + * @param classOfResponse Class of the type of A&AI objects to be returned * @return List A&AI objects matching the class */ @SuppressWarnings("unchecked") @@ -292,8 +295,7 @@ public class AaiCqResponse { /** * Returns a generic Vnf matching vnf name. * - * @param vnfName - * Name of the vnf to match + * @param vnfName Name of the vnf to match * @return generic Vnf */ public GenericVnf getGenericVnfByVnfName(String vnfName) { @@ -318,8 +320,7 @@ public class AaiCqResponse { /** * Returns a generic Vnf matching model invariant ID. * - * @param modelInvariantId - * Name of the vnf to match + * @param modelInvariantId Name of the vnf to match * @return generic Vnf */ public GenericVnf getGenericVnfByModelInvariantId(String modelInvariantId) { @@ -344,8 +345,7 @@ public class AaiCqResponse { /** * Returns a generic Vnf of a given VF Module ID. * - * @param vfModuleModelInvariantId - * of the vf module for which vnf is to be returned + * @param vfModuleModelInvariantId of the vf module for which vnf is to be returned * @return generic Vnf */ public GenericVnf getGenericVnfByVfModuleModelInvariantId(String vfModuleModelInvariantId) { @@ -355,7 +355,7 @@ public class AaiCqResponse { // Iterate through all the vfModules of that generic Vnf for (VfModule vfMod : genVnf.getVfModules().getVfModule()) { if (vfMod.getModelInvariantId() != null - && vfMod.getModelInvariantId().equals(vfModuleModelInvariantId)) { + && vfMod.getModelInvariantId().equals(vfModuleModelInvariantId)) { return genVnf; } } @@ -502,8 +502,7 @@ public class AaiCqResponse { VfModule vfModule = null; for (VfModule vfMod : this.getAllVfModules()) { - if (vfMod.getModelInvariantId() != null - && vfModelInvariantId.equals(vfMod.getModelInvariantId())) { + if (vfMod.getModelInvariantId() != null && vfModelInvariantId.equals(vfMod.getModelInvariantId())) { vfModule = vfMod; } @@ -560,28 +559,25 @@ public class AaiCqResponse { } /** - * Get the count of vfModules matching customizationId, InvariantId and - * VersionId. + * Get the count of vfModules matching customizationId, InvariantId and VersionId. * - * @param custId - * ModelCustomizationId - * @param invId - * ModelInvariantId - * @param verId - * ModelVersionId + * @param custId ModelCustomizationId + * @param invId ModelInvariantId + * @param verId ModelVersionId * @return Returns the count of vf modules */ public int getVfModuleCount(String custId, String invId, String verId) { List<VfModule> vfModuleList = this.getAllVfModules(); int count = 0; for (VfModule vfModule : vfModuleList) { - if (vfModule.getModelCustomizationId() != null && vfModule.getModelInvariantId() != null - && vfModule.getModelVersionId() != null) { - if (vfModule.getModelCustomizationId().equals(custId) - && vfModule.getModelInvariantId().equals(invId) + if (vfModule.getModelCustomizationId() == null || vfModule.getModelInvariantId() == null + || vfModule.getModelVersionId() == null) { + continue; + } + + if (vfModule.getModelCustomizationId().equals(custId) && vfModule.getModelInvariantId().equals(invId) && vfModule.getModelVersionId().equals(verId)) { - count = count + 1; - } + count = count + 1; } } return count; diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java index fca1aa2e9..499d1a7c9 100644 --- a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java +++ b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java @@ -31,6 +31,7 @@ import lombok.ToString; @Setter @ToString public class CdsResponse implements Serializable { + private static final long serialVersionUID = 2590429952699969650L; private String requestId; private String status; diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/api/CdsProcessorListener.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/api/CdsProcessorListener.java index c07c559c4..fb4c6ed79 100644 --- a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/api/CdsProcessorListener.java +++ b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/api/CdsProcessorListener.java @@ -26,7 +26,9 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOu * the received messages appropriately, it needs to implement {@link CdsProcessorListener}. * </p> * - * <p>Here is a sample implementation of a listener: + * <p> + * Here is a sample implementation of a listener: + * * <pre> * new CdsProcessorListener { * @@ -49,11 +51,10 @@ public interface CdsProcessorListener { /** * Implements the workflow upon receiving the message from the server side. * - * <p>Note that the CDS client-server communication is configured to use a streaming approach, which means when - * client - * sends an event, the server can reply with multiple sub-responses until full completion of the processing. Hence, - * it is up to the implementation of this method to process the received message using {@link - * ExecutionServiceOutput#getStatus()#getEventType()}</p> + * <p>Note that the CDS client-server communication is configured to use a streaming approach, which means when a + * client sends an event, the server can reply with multiple sub-responses until full completion of the processing. + * Hence, it is up to the implementation of this method to process the received message using the + * getStatus().getEventType() method of {@link ExecutionServiceOutput} * * @param message ExecutionServiceOutput received by the CDS grpc server */ diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java index 2ee47a9fc..643c629b3 100644 --- a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java +++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java @@ -41,9 +41,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class RestManager { - private static final Logger logger = LoggerFactory.getLogger(RestManager.class); + // Constants for string literals + private static final String CONTENT_TYPE = "Content-Type"; + public class Pair<A, B> { public final A first; public final B second; @@ -69,7 +71,7 @@ public class RestManager { Map<String, String> headers, String contentType, String body) { HttpPut put = new HttpPut(url); addHeaders(put, username, password, headers); - put.addHeader("Content-Type", contentType); + put.addHeader(CONTENT_TYPE, contentType); try { StringEntity input = new StringEntity(body); input.setContentType(contentType); @@ -96,7 +98,7 @@ public class RestManager { Map<String, String> headers, String contentType, String body) { HttpPost post = new HttpPost(url); addHeaders(post, username, password, headers); - post.addHeader("Content-Type", contentType); + post.addHeader(CONTENT_TYPE, contentType); try { StringEntity input = new StringEntity(body); input.setContentType(contentType); @@ -141,7 +143,7 @@ public class RestManager { HttpDeleteWithBody delete = new HttpDeleteWithBody(url); addHeaders(delete, username, password, headers); if (body != null && !body.isEmpty()) { - delete.addHeader("Content-Type", contentType); + delete.addHeader(CONTENT_TYPE, contentType); try { StringEntity input = new StringEntity(body); input.setContentType(contentType); diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java index 6e2494b72..d8933c86c 100644 --- a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java @@ -142,7 +142,7 @@ public final class SoManager { final String vfModuleInstanceId, final SoRequest request) { return executors.submit(new AsyncSoRestCallThread(requestId, callback, serviceInstanceId, vnfInstanceId, - vfModuleInstanceId, request, this.url, this.user, this.password)); + vfModuleInstanceId, request, this)); } /** @@ -173,18 +173,16 @@ public final class SoManager { final SoCallback callback, final String serviceInstanceId, final String vnfInstanceId, final String vfModuleInstanceId, final SoRequest request, - final String url, - final String user, - final String password) { + final SoManager callingSoManager) { this.requestId = requestId; this.callback = callback; this.serviceInstanceId = serviceInstanceId; this.vnfInstanceId = vnfInstanceId; this.vfModuleInstanceId = vfModuleInstanceId; this.request = request; - this.baseUrl = url; - this.user = user; - this.password = password; + this.baseUrl = callingSoManager.url; + this.user = callingSoManager.user; + this.password = callingSoManager.password; } /** diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java index 406e35d33..14382f0e9 100644 --- a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java @@ -125,45 +125,7 @@ public final class VfcManager implements Runnable { } try { - VfcResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VfcResponse.class); - NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetails.second); - String body = Serialization.gsonPretty.toJson(response); - logger.debug("Response to VFC Heal post:"); - logger.debug(body); - - String jobId = response.getJobId(); - int attemptsLeft = 20; - - String urlGet = vfcUrlBase + "/jobs/" + jobId; - VfcResponse responseGet = null; - - while (attemptsLeft-- > 0) { - NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", "VFC", urlGet); - Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers); - responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.second, VfcResponse.class); - NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetailsGet.second); - responseGet.setRequestId(vfcRequest.getRequestId().toString()); - body = Serialization.gsonPretty.toJson(responseGet); - logger.debug("Response to VFC Heal get:"); - logger.debug(body); - - String responseStatus = responseGet.getResponseDescriptor().getStatus(); - if (httpDetailsGet.first == 200 - && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { - logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); - this.callback.onResponse(responseGet); - break; - } - Thread.sleep(20000); - } - boolean isTimeout = (attemptsLeft <= 0) && (responseGet != null) - && (responseGet.getResponseDescriptor() != null); - isTimeout = isTimeout && (responseGet.getResponseDescriptor().getStatus() != null) - && (!responseGet.getResponseDescriptor().getStatus().isEmpty()); - if (isTimeout) { - logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); - this.callback.onResponse(responseGet); - } + handleVfcResponse(headers, httpDetails, vfcUrl); } catch (JsonSyntaxException e) { logger.error("Failed to deserialize into VfcResponse {}", e.getLocalizedMessage(), e); } catch (InterruptedException e) { @@ -175,6 +137,57 @@ public final class VfcManager implements Runnable { } /** + * Handle a VFC response message. + * + * @param headers the headers in the response + * @param httpDetails the HTTP details in the response + * @param vfcUrl the response URL + * @throws InterruptedException on errors in the response + */ + private void handleVfcResponse(Map<String, String> headers, Pair<Integer, String> httpDetails, String vfcUrl) + throws InterruptedException { + VfcResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VfcResponse.class); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetails.second); + String body = Serialization.gsonPretty.toJson(response); + logger.debug("Response to VFC Heal post:"); + logger.debug(body); + + String jobId = response.getJobId(); + int attemptsLeft = 20; + + String urlGet = vfcUrlBase + "/jobs/" + jobId; + VfcResponse responseGet = null; + + while (attemptsLeft-- > 0) { + NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", "VFC", urlGet); + Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers); + responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.second, VfcResponse.class); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetailsGet.second); + responseGet.setRequestId(vfcRequest.getRequestId().toString()); + body = Serialization.gsonPretty.toJson(responseGet); + logger.debug("Response to VFC Heal get:"); + logger.debug(body); + + String responseStatus = responseGet.getResponseDescriptor().getStatus(); + if (httpDetailsGet.first == 200 + && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { + logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); + this.callback.onResponse(responseGet); + return; + } + Thread.sleep(20000); + } + boolean isTimeout = (attemptsLeft <= 0) && (responseGet != null) + && (responseGet.getResponseDescriptor() != null); + isTimeout = isTimeout && (responseGet.getResponseDescriptor().getStatus() != null) + && (!responseGet.getResponseDescriptor().getStatus().isEmpty()); + if (isTimeout) { + logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); + this.callback.onResponse(responseGet); + } + } + + /** * Protected setter for rest manager to allow mocked rest manager to be used for testing. * * @param restManager the test REST manager diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java index 756253c47..793babf24 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java @@ -157,8 +157,8 @@ public class AaiSimulatorJaxRs { @Produces("application/json") public String getByVnfName(@QueryParam("vnf-name") final String vnfName) { if (GETFAIL.equals(vnfName)) { - return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" - + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not" + + " found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs" + "/generic-vnf\",\"ERR.5.4.6114\"]}}}"; } diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java index 6c1a05753..f21fb6f38 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -21,12 +21,12 @@ package org.onap.policy.simulators; -import java.io.IOException; import java.util.Properties; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.common.gson.GsonMessageBodyHandler; +import org.onap.policy.common.parameters.ParameterRuntimeException; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.network.NetworkUtil; @@ -49,11 +49,12 @@ public class Util { public static final int SDNCSIM_SERVER_PORT = 6670; public static final int DMAAPSIM_SERVER_PORT = 3904; + private static final String CANNOT_PROCESS_PARAMETERS = "cannot parse parameters "; private static final String CANNOT_CONNECT = "cannot connect to port "; private static final String LOCALHOST = "localhost"; private Util() { - // Prevent instantiation of thic class + // Prevent instantiation of this class } /** @@ -61,11 +62,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ - public static HttpServletServer buildAaiSim() throws InterruptedException, IOException { + public static HttpServletServer buildAaiSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true); + .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -79,11 +79,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ - public static HttpServletServer buildSdncSim() throws InterruptedException, IOException { + public static HttpServletServer buildSdncSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true); + .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -98,11 +97,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ - public static HttpServletServer buildSoSim() throws InterruptedException, IOException { + public static HttpServletServer buildSoSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true); + .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -116,11 +114,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ - public static HttpServletServer buildVfcSim() throws InterruptedException, IOException { + public static HttpServletServer buildVfcSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true); + .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -134,11 +131,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ - public static HttpServletServer buildGuardSim() throws InterruptedException, IOException { + public static HttpServletServer buildGuardSim() throws InterruptedException { HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(GUARDSIM_SERVER_NAME, - LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true); + LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true); testServer.setSerializationProvider(GsonMessageBodyHandler.class.getName()); testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); @@ -153,21 +149,25 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs - * @throws CoderException if the server parameters cannot be loaded */ - public static HttpServletServer buildDmaapSim() throws InterruptedException, IOException, CoderException { + public static HttpServletServer buildDmaapSim() throws InterruptedException { String json = ResourceUtils.getResourceAsString("org/onap/policy/simulators/dmaap/DmaapParameters.json"); - DmaapSimParameterGroup params = new StandardCoder().decode(json, DmaapSimParameterGroup.class); + DmaapSimParameterGroup params = null; + try { + params = new StandardCoder().decode(json, DmaapSimParameterGroup.class); + } catch (CoderException ce) { + throw new ParameterRuntimeException( + CANNOT_PROCESS_PARAMETERS + "org/onap/policy/simulators/dmaap/DmaapParameters.json", ce); + } DmaapSimProvider.setInstance(new DmaapSimProvider(params)); Properties props = DmaapSimRestServer.getServerProperties(params.getRestServerParameters()); final String svcpfx = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." - + params.getRestServerParameters().getName(); + + params.getRestServerParameters().getName(); props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, - Integer.toString(DMAAPSIM_SERVER_PORT)); + Integer.toString(DMAAPSIM_SERVER_PORT)); props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(props).get(0); |