diff options
40 files changed, 592 insertions, 436 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 49ba336e3f..c75aa9a67e 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -22,10 +22,6 @@ package org.onap.so.openstack.utils; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.woorea.openstack.heat.model.CreateStackParam; -import com.woorea.openstack.heat.model.Stack; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; @@ -52,7 +48,6 @@ import org.onap.so.logger.MessageEnum; import org.onap.so.openstack.beans.HeatStatus; import org.onap.so.openstack.beans.StackInfo; import org.onap.so.openstack.exceptions.MsoAdapterException; -import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; import org.onap.so.openstack.exceptions.MsoOpenstackException; import org.onap.so.openstack.mappers.StackInfoMapper; @@ -62,7 +57,11 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableSet; +import com.woorea.openstack.heat.model.CreateStackParam; +import com.woorea.openstack.heat.model.Stack; @Component public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { @@ -299,7 +298,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { responseBody = getQueryBody((java.io.InputStream) response.getEntity()); if (responseBody != null) { if (logger.isDebugEnabled()) { - logger.debug("Multicloud Create Response Body: " + responseBody.toString()); + logger.debug("Multicloud Create Response Body: {}", responseBody); } Stack workloadStack = getWorkloadStack(responseBody.getWorkloadStatusReason()); if (workloadStack != null && !responseBody.getWorkloadStatus().equals("GET_FAILED") @@ -354,7 +353,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { } } if (workloadStack != null) - logger.debug("Multicloud getWorkloadStack() returning Stack Object: {} ", workloadStack.toString()); + logger.debug("Multicloud getWorkloadStack() returning Stack Object: {} ", workloadStack); return workloadStack; } @@ -457,8 +456,8 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { Response response = multicloudClient.post(multicloudRequest); if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) { if (logger.isDebugEnabled()) - logger.debug( - "Multicloud AAI update request failed: " + response.getStatus() + response.getStatusInfo()); + logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), + response.getStatusInfo()); return; } @@ -470,14 +469,14 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { Integer.parseInt(this.environment.getProperty(createPollIntervalProp, CREATE_POLL_INTERVAL_DEFAULT)); int pollTimeout = (timeoutMinutes * 60) + updatePollInterval; boolean updateTimedOut = false; - logger.debug("updatePollInterval=" + updatePollInterval + ", pollTimeout=" + pollTimeout); + logger.debug("updatePollInterval={}, pollTimeout={}", updatePollInterval, pollTimeout); StackInfo stackInfo = null; while (true) { try { stackInfo = queryStack(cloudSiteId, cloudOwner, tenantId, workloadId); if (logger.isDebugEnabled()) - logger.debug(stackInfo.getStatus() + " (" + workloadId + ")"); + logger.debug("{} ({})", stackInfo.getStatus(), workloadId); if (HeatStatus.UPDATING.equals(stackInfo.getStatus())) { if (pollTimeout <= 0) { @@ -494,7 +493,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { pollTimeout -= updatePollInterval; if (logger.isDebugEnabled()) - logger.debug("pollTimeout remaining: " + pollTimeout); + logger.debug("pollTimeout remaining: {}", pollTimeout); } else { break; } @@ -508,15 +507,14 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { if (updateTimedOut) { if (logger.isDebugEnabled()) logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), - response.getStatusInfo().toString()); + response.getStatusInfo()); } else if (!HeatStatus.UPDATED.equals(stackInfo.getStatus())) { if (logger.isDebugEnabled()) logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), - response.getStatusInfo().toString()); + response.getStatusInfo()); } else { if (logger.isDebugEnabled()) - logger.debug("Multicloud AAI update successful: {} {}", response.getStatus(), - response.getStatusInfo().toString()); + logger.debug("Multicloud AAI update successful: {} {}", response.getStatus(), response.getStatusInfo()); } } @@ -543,12 +541,12 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { int deletePollTimeout = pollTimeout; boolean createTimedOut = false; StringBuilder stackErrorStatusReason = new StringBuilder(""); - logger.debug("createPollInterval=" + createPollInterval + ", pollTimeout=" + pollTimeout); + logger.debug("createPollInterval={}, pollTimeout={} ", createPollInterval, pollTimeout); while (true) { try { stackInfo = queryStack(cloudSiteId, cloudOwner, tenantId, instanceId); - logger.debug(stackInfo.getStatus() + " (" + instanceId + ")"); + logger.debug("{} ({})", stackInfo.getStatus(), instanceId); if (HeatStatus.BUILDING.equals(stackInfo.getStatus())) { // Stack creation is still running. @@ -567,7 +565,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { sleep(createPollInterval * 1000L); pollTimeout -= createPollInterval; - logger.debug("pollTimeout remaining: " + pollTimeout); + logger.debug("pollTimeout remaining: {}", pollTimeout); } else { // save off the status & reason msg before we attempt delete stackErrorStatusReason @@ -596,7 +594,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { while (!deleted) { try { StackInfo queryInfo = queryStack(cloudSiteId, cloudOwner, tenantId, instanceId); - logger.debug("Deleting " + instanceId + ", status: " + queryInfo.getStatus()); + logger.debug("Deleting {}, status: {}", instanceId, queryInfo.getStatus()); if (HeatStatus.DELETING.equals(queryInfo.getStatus())) { if (deletePollTimeout <= 0) { logger.error(String.format("%s %s %s %s %s %s %s %s %d %s", @@ -610,7 +608,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { deletePollTimeout -= deletePollInterval; } } else if (HeatStatus.NOTFOUND.equals(queryInfo.getStatus())) { - logger.debug("DELETE_COMPLETE for " + instanceId); + logger.debug("DELETE_COMPLETE for {}", instanceId); deleted = true; continue; } else { @@ -664,7 +662,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { while (!deleted) { try { StackInfo queryInfo = queryStack(cloudSiteId, cloudOwner, tenantId, instanceId); - logger.debug("Deleting " + instanceId + ", status: " + queryInfo.getStatus()); + logger.debug("Deleting {}, status: {}", instanceId, queryInfo.getStatus()); if (HeatStatus.DELETING.equals(queryInfo.getStatus())) { if (deletePollTimeout <= 0) { logger.error(String.format("%s %s %s %s %s %s %s %s %d %s", @@ -678,7 +676,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { deletePollTimeout -= deletePollInterval; } } else if (HeatStatus.NOTFOUND.equals(queryInfo.getStatus())) { - logger.debug("DELETE_COMPLETE for " + instanceId); + logger.debug("DELETE_COMPLETE for {}", instanceId); deleted = true; continue; } else { @@ -730,7 +728,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { } else { // Get initial status, since it will have been null after the create. stackInfo = queryStack(cloudSiteId, cloudOwner, tenantId, instanceId); - logger.debug("Multicloud stack query status is: " + stackInfo.getStatus()); + logger.debug("Multicloud stack query status is: {}", stackInfo.getStatus()); } return stackInfo; } @@ -769,7 +767,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { try { return new ObjectMapper().readerFor(MulticloudCreateResponse.class).readValue(body); } catch (Exception e) { - logger.debug("Exception retrieving multicloud vfModule POST response body " + e); + logger.debug("Exception retrieving multicloud vfModule POST response body ", e); } return null; } @@ -786,7 +784,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { try { return new ObjectMapper().readerFor(MulticloudQueryResponse.class).readValue(body); } catch (Exception e) { - logger.debug("Exception retrieving multicloud workload query response body " + e); + logger.debug("Exception retrieving multicloud workload query response body ", e); } return null; } @@ -828,14 +826,11 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { client.addAdditionalHeader("Project", tenantId); } } catch (MalformedURLException e) { - logger.debug( - String.format("Encountered malformed URL error getting multicloud rest client %s", e.getMessage())); + logger.debug("Encountered malformed URL error getting multicloud rest client ", e); } catch (IllegalArgumentException e) { - logger.debug( - String.format("Encountered illegal argument getting multicloud rest client %s", e.getMessage())); + logger.debug("Encountered illegal argument getting multicloud rest client ", e); } catch (UriBuilderException e) { - logger.debug( - String.format("Encountered URI builder error getting multicloud rest client %s", e.getMessage())); + logger.debug("Encountered URI builder error getting multicloud rest client ", e); } return client; } @@ -989,7 +984,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { // There are lots of HeatStatus values, so this is a bit long... HeatStatus heatStatus = stackInfo.getStatus(); String statusMessage = stackInfo.getStatusMessage(); - logger.debug("HeatStatus = " + heatStatus + " msg = " + statusMessage); + logger.debug("HeatStatus = {} msg = {}", heatStatus, statusMessage); if (logger.isDebugEnabled()) { logger.debug(String.format("Stack Status: %s", heatStatus.toString())); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java index ad37b39f30..c575304ade 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java @@ -40,7 +40,7 @@ public class MulticloudQueryResponse implements Serializable { @JsonProperty("workload_status") private String workloadStatus; @JsonProperty("workload_status_reason") - private JsonNode workloadStatusReason; + private transient JsonNode workloadStatusReason; @JsonCreator public MulticloudQueryResponse(@JsonProperty("template_type") String templateType, diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java index cc3ec52c7a..3a4df68f02 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java @@ -68,7 +68,7 @@ public class InstanceResourceList { public static List<Resource> getInstanceResourceList(final VnfResource vnfResource, final String uuiRequest) { - List<Resource> sequencedResourceList = new ArrayList<Resource>(); + List<Resource> sequencedResourceList = new ArrayList<>(); Gson gson = new Gson(); JsonObject servJsonObject = gson.fromJson(uuiRequest, JsonObject.class); JsonObject reqInputJsonObj = servJsonObject.getAsJsonObject("service").getAsJsonObject("parameters") @@ -117,7 +117,7 @@ public class InstanceResourceList { } private static List<Resource> getGroupResourceInstanceList(VnfResource vnfResource, JsonObject vfObj) { - List<Resource> sequencedResourceList = new ArrayList<Resource>(); + List<Resource> sequencedResourceList = new ArrayList<>(); if (vnfResource.getGroupOrder() != null && !StringUtils.isEmpty(vnfResource.getGroupOrder())) { String[] grpSequence = vnfResource.getGroupOrder().split(","); for (String grpType : grpSequence) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/Metadata.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/Metadata.java index f56fad3bcf..84b162e1a2 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/Metadata.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/Metadata.java @@ -31,7 +31,7 @@ public class Metadata implements Serializable { private static final long serialVersionUID = 4981393122007858950L; @JsonProperty("metadatum") - private List<Metadatum> metadatum = new ArrayList<Metadatum>(); + private List<Metadatum> metadatum = new ArrayList<>(); public List<Metadatum> getMetadatum() { return metadatum; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/AggregateRoute.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/AggregateRoute.java index a5eb9d86a7..96a6ab7bd2 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/AggregateRoute.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/AggregateRoute.java @@ -36,8 +36,6 @@ public class AggregateRoute implements Serializable, ShallowCopy<AggregateRoute> @Id @JsonProperty("route-id") private String routeId; - @JsonProperty("route-name") - private String routeName; @JsonProperty("network-start-address") private String networkStartAddress; @JsonProperty("cidr-mask") @@ -54,14 +52,6 @@ public class AggregateRoute implements Serializable, ShallowCopy<AggregateRoute> this.routeId = routeId; } - public String getRouteName() { - return routeName; - } - - public void setRouteName(String routeName) { - this.routeName = routeName; - } - public String getNetworkStartAddress() { return networkStartAddress; } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java index 841546b3b1..ebf722ef74 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/GenericVnf.java @@ -133,7 +133,7 @@ public class GenericVnf implements Serializable, ShallowCopy<GenericVnf> { @JsonProperty("model-info-generic-vnf") private ModelInfoGenericVnf modelInfoGenericVnf; @JsonProperty("instance-groups") - private List<InstanceGroup> instanceGroups = new ArrayList<InstanceGroup>(); + private List<InstanceGroup> instanceGroups = new ArrayList<>(); @JsonProperty("call-homing") private Boolean callHoming; @JsonProperty("nf-function") diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/LInterface.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/LInterface.java index 387d191409..db2785902a 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/LInterface.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/LInterface.java @@ -65,15 +65,15 @@ public class LInterface implements Serializable, ShallowCopy<LInterface> { @JsonProperty("allowed-address-pairs") private String allowedAddressPairs; @JsonProperty("vlans") - private List<Vlan> vlans = new ArrayList<Vlan>(); + private List<Vlan> vlans = new ArrayList<>(); @JsonProperty("sriov-vfs") - private List<SriovVf> sriovVfs = new ArrayList<SriovVf>(); + private List<SriovVf> sriovVfs = new ArrayList<>(); @JsonProperty("l-interfaces") - private List<LInterface> lInterfaces = new ArrayList<LInterface>(); + private List<LInterface> lInterfaces = new ArrayList<>(); @JsonProperty("l3-interface-ipv4-address-list") - private List<L3InterfaceIpv4AddressList> l3InterfaceIpv4AddressList = new ArrayList<L3InterfaceIpv4AddressList>(); + private List<L3InterfaceIpv4AddressList> l3InterfaceIpv4AddressList = new ArrayList<>(); @JsonProperty("l3-interface-ipv6-address-list") - private List<L3InterfaceIpv6AddressList> l3InterfaceIpv6AddressList = new ArrayList<L3InterfaceIpv6AddressList>(); + private List<L3InterfaceIpv6AddressList> l3InterfaceIpv6AddressList = new ArrayList<>(); public String getInterfaceName() { return interfaceName; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/PServer.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/PServer.java index d0bf1f588b..f3e28faf44 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/PServer.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/PServer.java @@ -41,9 +41,9 @@ public class PServer implements Serializable, ShallowCopy<PServer> { @JsonProperty("hostname") private String hostname; @JsonProperty("physical-links") - private List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>(); // TODO techincally there is a pInterface - // between (pserver <--> physical-link) - // but dont really need that pojo + private List<PhysicalLink> physicalLinks = new ArrayList<>(); // TODO techincally there is a pInterface + // between (pserver <--> physical-link) + // but dont really need that pojo public String getPserverId() { return pserverId; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceInstance.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceInstance.java index 0803bed574..6cc8aa368c 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceInstance.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceInstance.java @@ -79,7 +79,7 @@ public class ServiceInstance implements Serializable, ShallowCopy<ServiceInstanc @JsonProperty("instance-groups") private List<InstanceGroup> instanceGroups = new ArrayList<>(); @JsonProperty("service-proxies") - private List<ServiceProxy> serviceProxies = new ArrayList<ServiceProxy>(); + private List<ServiceProxy> serviceProxies = new ArrayList<>(); public void setServiceProxies(List<ServiceProxy> serviceProxies) { this.serviceProxies = serviceProxies; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceSubscription.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceSubscription.java index 05199b7f37..b677b1efd0 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceSubscription.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/ServiceSubscription.java @@ -41,7 +41,7 @@ public class ServiceSubscription implements Serializable, ShallowCopy<ServiceSub @JsonProperty("temp-ub-sub-account-id") private String tempUbSubAccountId; @JsonProperty("service-instances") - private List<ServiceInstance> serviceInstances = new ArrayList<ServiceInstance>(); + private List<ServiceInstance> serviceInstances = new ArrayList<>(); public String getServiceType() { return serviceType; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Vlan.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Vlan.java index 6951a23630..8c0db18d80 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Vlan.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Vlan.java @@ -62,9 +62,9 @@ public class Vlan implements Serializable, ShallowCopy<Vlan> { @JsonProperty("is-ip-unnumbered") private Boolean isIpUnnumbered; @JsonProperty("l3-interface-ipv4-address-list") - private List<L3InterfaceIpv4AddressList> l3InterfaceIpv4AddressList = new ArrayList<L3InterfaceIpv4AddressList>(); + private List<L3InterfaceIpv4AddressList> l3InterfaceIpv4AddressList = new ArrayList<>(); @JsonProperty("l3-interface-ipv6-address-list") - private List<L3InterfaceIpv6AddressList> l3InterfaceIpv6AddressList = new ArrayList<L3InterfaceIpv6AddressList>(); + private List<L3InterfaceIpv6AddressList> l3InterfaceIpv6AddressList = new ArrayList<>(); public String getVlanInterface() { return vlanInterface; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/VpnBondingLink.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/VpnBondingLink.java index 4ee8213e59..4e5b3557d8 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/VpnBondingLink.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/VpnBondingLink.java @@ -41,10 +41,10 @@ public class VpnBondingLink implements Serializable, ShallowCopy<VpnBondingLink> private String vpnBondingLinkId; @JsonProperty("configurations") - private List<Configuration> configurations = new ArrayList<Configuration>(); + private List<Configuration> configurations = new ArrayList<>(); @JsonProperty("service-proxies") - private List<ServiceProxy> serviceProxies = new ArrayList<ServiceProxy>(); + private List<ServiceProxy> serviceProxies = new ArrayList<>(); public String getVpnBondingLinkId() { return vpnBondingLinkId; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java index 573925ff3f..ea48c78dc0 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Optional; import org.modelmapper.ModelMapper; import org.modelmapper.convention.MatchingStrategies; +import org.onap.so.bpmn.servicedecomposition.bbobjects.AggregateRoute; import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; @@ -131,6 +132,10 @@ public class BBInputSetupMapperLayer { return modelMapper.map(aaiSegmentationAssignment, SegmentationAssignment.class); } + protected AggregateRoute mapAAIAggregateRoute(org.onap.aai.domain.yang.AggregateRoute aaiAggregateRoute) { + return modelMapper.map(aaiAggregateRoute, AggregateRoute.class); + } + protected CtagAssignment mapAAICtagAssignment(org.onap.aai.domain.yang.CtagAssignment aaiCtagAssignment) { return modelMapper.map(aaiCtagAssignment, CtagAssignment.class); } @@ -262,10 +267,21 @@ public class BBInputSetupMapperLayer { mapAllSubnetsIntoL3Network(aaiL3Network, network); mapAllCtagAssignmentsIntoL3Network(aaiL3Network, network); mapAllSegmentationAssignmentsIntoL3Network(aaiL3Network, network); + mapAllAggregateRoutesIntoL3Network(aaiL3Network, network); network.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiL3Network.getOrchestrationStatus())); return network; } + protected void mapAllAggregateRoutesIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network, + L3Network network) { + if (aaiL3Network.getAggregateRoutes() != null) { + for (org.onap.aai.domain.yang.AggregateRoute aaiAggregateRoute : aaiL3Network.getAggregateRoutes() + .getAggregateRoute()) { + network.getAggregateRoutes().add(mapAAIAggregateRoute(aaiAggregateRoute)); + } + } + } + protected void mapAllSegmentationAssignmentsIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network, L3Network network) { if (aaiL3Network.getSegmentationAssignments() != null) { diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json index 418396f290..9b32a4c446 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json @@ -69,5 +69,15 @@ } ] }, + "aggregateRoutes": { + "aggregateRoute": [ + { + "routeId": "routeId", + "networkStartAddress": "10.80.12.0", + "cidrMask": "23", + "ipVersion": "4" + } + ] + }, "relationshipList": null }
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/l3NetworkExpectedWithSubnet.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/l3NetworkExpectedWithSubnet.json index ccefe195c9..f65fe17a2e 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/l3NetworkExpectedWithSubnet.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/l3NetworkExpectedWithSubnet.json @@ -52,5 +52,13 @@ "segmentation-id": "segmentationId" } ], + "aggregate-routes": [ + { + "route-id": "routeId", + "network-start-address": "10.80.12.0", + "cidr-mask": "23", + "ip-version": "4" + } + ], "model-info-network": null } diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java index 21847e1c4e..7d5bb0dcf1 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java @@ -33,7 +33,7 @@ public class WorkflowException implements Serializable { private final int errorCode; private final String errorMessage; private final String workStep; - private transient TargetEntities extSystemErrorSource; + private TargetEntities extSystemErrorSource; /** * Constructor diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeActivateSDNCNetworkResource.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeActivateSDNCNetworkResource.groovy index 8e560cc09d..1a689d426c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeActivateSDNCNetworkResource.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeActivateSDNCNetworkResource.groovy @@ -53,7 +53,7 @@ public class DeActivateSDNCNetworkResource extends AbstractServiceTaskProcessor MsoUtils msoUtils = new MsoUtils() - public void preProcessRequest(DelegateExecution execution) { + void preProcessRequest(DelegateExecution execution) { logger.info(" ***** Started preProcessRequest *****") @@ -104,7 +104,7 @@ public class DeActivateSDNCNetworkResource extends AbstractServiceTaskProcessor } } - public void prepareSDNCRequest(DelegateExecution execution) { + void prepareSDNCRequest(DelegateExecution execution) { logger.info(" ***** Started prepareSDNCRequest *****") try { @@ -390,7 +390,7 @@ public class DeActivateSDNCNetworkResource extends AbstractServiceTaskProcessor logger.info(" ***** Exit prepareSDNCRequest *****") } - public void prepareUpdateAfterDeActivateSDNCResource(DelegateExecution execution) { + void prepareUpdateAfterDeActivateSDNCResource(DelegateExecution execution) { String resourceInput = execution.getVariable("resourceInput") ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class) String operType = resourceInputObj.getOperationType() @@ -429,7 +429,7 @@ public class DeActivateSDNCNetworkResource extends AbstractServiceTaskProcessor execution.setVariable("CVFMI_updateResOperStatusRequest", body) } - public void postDeactivateSDNCCall(DelegateExecution execution) { + void postDeactivateSDNCCall(DelegateExecution execution) { logger.info(" ***** Started prepareSDNCRequest *****") String responseCode = execution.getVariable(Prefix + "sdncDeleteReturnCode") String responseObj = execution.getVariable(Prefix + "SuccessIndicator") @@ -438,7 +438,7 @@ public class DeActivateSDNCNetworkResource extends AbstractServiceTaskProcessor logger.info(" ***** Exit prepareSDNCRequest *****") } - public void sendSyncResponse(DelegateExecution execution) { + void sendSyncResponse(DelegateExecution execution) { logger.debug(" *** sendSyncResponse *** ") try { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteVFCNSResource.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteVFCNSResource.groovy index 9b269c734f..642609a970 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteVFCNSResource.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteVFCNSResource.groovy @@ -63,14 +63,14 @@ public class DeleteVFCNSResource extends AbstractServiceTaskProcessor { logger.info(" ***** end preProcessRequest *****") } - public void postProcessRequest (DelegateExecution execution) { + void postProcessRequest (DelegateExecution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") logger.info(" ***** start postProcessRequest *****") logger.info(" ***** end postProcessRequest *****") } - public void sendSyncResponse (DelegateExecution execution) { + void sendSyncResponse (DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.debug( " *** sendSyncResponse *** ") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy index bf52b11de2..64d9827c7c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy @@ -83,7 +83,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { JsonUtils jsonUtil = new JsonUtils() CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create() - public void preProcessRequest (DelegateExecution execution) { + void preProcessRequest (DelegateExecution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") String msg = "" logger.trace("preProcessRequest") @@ -286,7 +286,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit preProcessRequest") } - public void getAAICustomerById (DelegateExecution execution) { + void getAAICustomerById (DelegateExecution execution) { // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId} try { @@ -306,7 +306,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { } - public void putServiceInstance(DelegateExecution execution) { + void putServiceInstance(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.trace("putServiceInstance") String msg = "" @@ -380,7 +380,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit putServiceInstance") } - public void preProcessSDNCAssignRequest(DelegateExecution execution) { + void preProcessSDNCAssignRequest(DelegateExecution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") String msg = "" logger.trace("preProcessSDNCAssignRequest") @@ -479,7 +479,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit preProcessSDNCAssignRequest") } - public void postProcessSDNCAssign (DelegateExecution execution) { + void postProcessSDNCAssign (DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.trace("postProcessSDNCAssign") try { @@ -518,7 +518,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit postProcessSDNCAssign") } - public void postProcessAAIGET2(DelegateExecution execution) { + void postProcessAAIGET2(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.trace("postProcessAAIGET2") String msg = "" @@ -561,7 +561,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit postProcessAAIGET2") } - public void preProcessRollback (DelegateExecution execution) { + void preProcessRollback (DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.trace("preProcessRollback") try { @@ -582,7 +582,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit preProcessRollback") } - public void postProcessRollback (DelegateExecution execution) { + void postProcessRollback (DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.trace("postProcessRollback") String msg = "" @@ -603,7 +603,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit postProcessRollback") } - public void createProject(DelegateExecution execution) { + void createProject(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.trace("createProject") @@ -631,7 +631,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { logger.trace("Exit createProject") } - public void createOwningEntity(DelegateExecution execution) { + void createOwningEntity(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") logger.trace("createOwningEntity") String msg = ""; @@ -679,7 +679,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { // Build Error Section // ******************************* - public void processJavaException(DelegateExecution execution){ + void processJavaException(DelegateExecution execution){ def isDebugEnabled=execution.getVariable("isDebugLogEnabled") try{ diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java index 357b571a5c..48061db887 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/dmaap/PnfEventReadyDmaapClient.java @@ -90,7 +90,7 @@ public class PnfEventReadyDmaapClient implements DmaapClient { @Override public synchronized Runnable unregister(String pnfCorrelationId) { logger.debug("unregistering from pnf ready dmaap event for pnf correlation id: {}", pnfCorrelationId); - Runnable runnable = runnable = pnfCorrelationIdToThreadMap.remove(pnfCorrelationId); + Runnable runnable = pnfCorrelationIdToThreadMap.remove(pnfCorrelationId); synchronized (updateInfoMap) { for (int i = updateInfoMap.size() - 1; i >= 0; i--) { if (!updateInfoMap.get(i).containsKey("pnfCorrelationId")) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java index 579e7b72df..2f05eb5f2d 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java @@ -863,23 +863,23 @@ public class ServicePluginFactory { HttpClient client = HttpClientBuilder.create().build(); - if ("POST".equals(methodType.toUpperCase())) { + if ("POST".equalsIgnoreCase(methodType)) { HttpPost httpPost = new HttpPost(msbUrl); httpPost.setConfig(requestConfig); httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); method = httpPost; - } else if ("PUT".equals(methodType.toUpperCase())) { + } else if ("PUT".equalsIgnoreCase(methodType)) { HttpPut httpPut = new HttpPut(msbUrl); httpPut.setConfig(requestConfig); httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); method = httpPut; - } else if ("GET".equals(methodType.toUpperCase())) { + } else if ("GET".equalsIgnoreCase(methodType)) { HttpGet httpGet = new HttpGet(msbUrl); httpGet.setConfig(requestConfig); httpGet.addHeader("X-FromAppId", "MSO"); httpGet.addHeader("Accept", "application/json"); method = httpGet; - } else if ("DELETE".equals(methodType.toUpperCase())) { + } else if ("DELETE".equalsIgnoreCase(methodType)) { HttpDelete httpDelete = new HttpDelete(msbUrl); httpDelete.setConfig(requestConfig); method = httpDelete; diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java index f7f5d78604..e301edb0fd 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java @@ -32,9 +32,9 @@ public class DSLNodeKey implements QueryStep { private boolean not = false; private final StringBuilder query = new StringBuilder(); private final String keyName; - private final List<String> values; + private final List<Object> values; - public DSLNodeKey(String keyName, String... value) { + public DSLNodeKey(String keyName, Object... value) { this.keyName = keyName; this.values = Arrays.asList(value); @@ -54,14 +54,18 @@ public class DSLNodeKey implements QueryStep { result.append(" !"); } result.append("('").append(keyName).append("', "); - List<String> temp = new ArrayList<>(); - for (String item : values) { + List<Object> temp = new ArrayList<>(); + for (Object item : values) { if ("null".equals(item)) { temp.add(String.format("' %s '", item)); } else if ("".equals(item)) { temp.add("' '"); } else { - temp.add(String.format("'%s'", item)); + if (item instanceof String) { + temp.add(String.format("'%s'", item)); + } else { + temp.add(item); + } } } result.append(Joiner.on(", ").join(temp)).append(")"); diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java index 2fdd6574e5..87d4d84cac 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java @@ -45,7 +45,7 @@ public class __ { return __.<DSLNode>start(new DSLNode(name, key)); } - public static DSLNodeKey key(String keyName, String... value) { + public static DSLNodeKey key(String keyName, Object... value) { return new DSLNodeKey(keyName, value); } diff --git a/common/src/main/java/org/onap/so/utils/TargetEntities.java b/common/src/main/java/org/onap/so/utils/TargetEntities.java index 94385ec8ea..67016a1fa9 100644 --- a/common/src/main/java/org/onap/so/utils/TargetEntities.java +++ b/common/src/main/java/org/onap/so/utils/TargetEntities.java @@ -20,6 +20,8 @@ package org.onap.so.utils; -public interface TargetEntities { +import java.io.Serializable; + +public interface TargetEntities extends Serializable { } diff --git a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java index 6e55fe17fa..590e83827b 100644 --- a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java +++ b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java @@ -108,4 +108,14 @@ public class DSLQueryBuilderTest { builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')")); assertTrue(builder.equals(builder)); } + + + @Test + public void mixedTypeTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + __.key("cloud-owner", "owner"), __.key("cloud-region-id", "id"))); + builder.to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", 167), __.key("my-boolean", true)).output()); + assertTrue(builder.equals( + "cloud-region('cloud-owner', 'owner')('cloud-region-id', 'id') > vlan-tag*('vlan-id-outer', 167)('my-boolean', true)")); + } } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java index 5dbe44f58b..5ae0cea549 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Actions.java @@ -20,6 +20,8 @@ package org.onap.so.apihandlerinfra; -public interface Actions { +import java.io.Serializable; + +public interface Actions extends Serializable { } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GenericStringConverter.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GenericStringConverter.java new file mode 100644 index 0000000000..80144d8ca1 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GenericStringConverter.java @@ -0,0 +1,33 @@ +package org.onap.so.apihandlerinfra; + +import java.net.URI; +import java.util.Set; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; +import org.springframework.core.convert.TypeDescriptor; +import org.springframework.core.convert.converter.GenericConverter; +import org.springframework.stereotype.Component; +import com.google.common.collect.ImmutableSet; + +@Component +@ConfigurationPropertiesBinding +public class GenericStringConverter implements GenericConverter { + + @Autowired + private HealthCheckConverter converter; + + @Override + public Set<ConvertiblePair> getConvertibleTypes() { + + ConvertiblePair[] pairs = new ConvertiblePair[] {new ConvertiblePair(String.class, Subsystem.class), + new ConvertiblePair(String.class, URI.class)}; + return ImmutableSet.copyOf(pairs); + } + + @Override + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + + return converter.convert(source, sourceType, targetType); + + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java index 3d4b2c76fb..0379ae3578 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java @@ -25,11 +25,8 @@ package org.onap.so.apihandlerinfra; import java.net.URI; import java.util.Collections; -import org.onap.so.logger.LoggingAnchor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import java.util.List; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.transaction.Transactional; import javax.ws.rs.DefaultValue; @@ -42,14 +39,20 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import org.apache.http.HttpStatus; +import org.onap.so.apihandlerinfra.HealthCheckConfig.Endpoint; +import org.onap.so.logger.LoggingAnchor; import org.onap.so.logger.MessageEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; -import org.springframework.http.HttpMethod; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -59,45 +62,38 @@ import io.swagger.annotations.ApiOperation; @Api(value = "/globalhealthcheck", description = "APIH Infra Global Health Check") public class GlobalHealthcheckHandler { private static Logger logger = LoggerFactory.getLogger(GlobalHealthcheckHandler.class); - private static final String CONTEXTPATH_PROPERTY = "management.context-path"; - private static final String PROPERTY_DOMAIN = "mso.health.endpoints"; - private static final String CATALOGDB_PROPERTY = PROPERTY_DOMAIN + ".catalogdb"; - private static final String REQUESTDB_PROPERTY = PROPERTY_DOMAIN + ".requestdb"; - private static final String SDNC_PROPERTY = PROPERTY_DOMAIN + ".sdnc"; - private static final String OPENSTACK_PROPERTY = PROPERTY_DOMAIN + ".openstack"; - private static final String BPMN_PROPERTY = PROPERTY_DOMAIN + ".bpmn"; - private static final String ASDC_PROPERTY = PROPERTY_DOMAIN + ".asdc"; - private static final String REQUESTDBATTSVC_PROPERTY = PROPERTY_DOMAIN + ".requestdbattsvc"; - private static final String DEFAULT_PROPERTY_VALUE = ""; + protected static final String CONTEXTPATH_PROPERTY = "management.endpoints.web.base-path"; + protected static final String PROPERTY_DOMAIN = "mso.health"; + protected static final String CATALOGDB_PROPERTY = PROPERTY_DOMAIN + ".endpoints.catalogdb"; + protected static final String REQUESTDB_PROPERTY = PROPERTY_DOMAIN + ".endpoints.requestdb"; + protected static final String SDNC_PROPERTY = PROPERTY_DOMAIN + ".endpoints.sdnc"; + protected static final String OPENSTACK_PROPERTY = PROPERTY_DOMAIN + ".endpoints.openstack"; + protected static final String BPMN_PROPERTY = PROPERTY_DOMAIN + ".endpoints.bpmn"; + protected static final String ASDC_PROPERTY = PROPERTY_DOMAIN + ".endpoints.asdc"; + protected static final String REQUESTDBATTSVC_PROPERTY = PROPERTY_DOMAIN + ".endpoints.requestdbattsvc"; + protected static final String MSO_AUTH_PROPERTY = PROPERTY_DOMAIN + ".auth"; + protected static final String DEFAULT_PROPERTY_VALUE = ""; // e.g. /manage private String actuatorContextPath; - private String endpointCatalogdb; - private String endpointRequestdb; - private String endpointSdnc; - private String endpointOpenstack; - private String endpointBpmn; - private String endpointAsdc; - private String endpointRequestdbAttsvc; @Autowired private Environment env; @Autowired private RestTemplate restTemplate; - private final String health = "/health"; + @Autowired + private HealthCheckConfig config; + + private static final String HEALTH = "/health"; + + private String msoAuth; @PostConstruct protected void init() { actuatorContextPath = env.getProperty(CONTEXTPATH_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); - endpointCatalogdb = env.getProperty(CATALOGDB_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); - endpointRequestdb = env.getProperty(REQUESTDB_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); - endpointSdnc = env.getProperty(SDNC_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); - endpointOpenstack = env.getProperty(OPENSTACK_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); - endpointBpmn = env.getProperty(BPMN_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); - endpointAsdc = env.getProperty(ASDC_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); - endpointRequestdbAttsvc = env.getProperty(REQUESTDBATTSVC_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + msoAuth = env.getProperty(MSO_AUTH_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); } @GET @@ -108,29 +104,25 @@ public class GlobalHealthcheckHandler { @Context ContainerRequestContext requestContext) { Response HEALTH_CHECK_RESPONSE = null; // Build internal response object - HealthcheckResponse rsp = new HealthcheckResponse(); + HealthCheckResponse rsp = new HealthCheckResponse(); try { // Generated RequestId String requestId = requestContext.getProperty("requestId").toString(); logger.info(LoggingAnchor.TWO, MessageEnum.APIH_GENERATED_REQUEST_ID.toString(), requestId); - // set APIH status, this is the main entry point - rsp.setApih(HealthcheckStatus.UP.toString()); - // set BPMN - rsp.setBpmn(querySubsystemHealth(MsoSubsystems.BPMN)); - // set SDNCAdapter - rsp.setSdncAdapter(querySubsystemHealth(MsoSubsystems.SDNC)); - // set ASDCController - rsp.setAsdcController(querySubsystemHealth(MsoSubsystems.ASDC)); - // set CatalogDbAdapter - rsp.setCatalogdbAdapter(querySubsystemHealth(MsoSubsystems.CATALOGDB)); - // set RequestDbAdapter - rsp.setRequestdbAdapter(querySubsystemHealth(MsoSubsystems.REQUESTDB)); - // set OpenStackAdapter - rsp.setOpenstackAdapter(querySubsystemHealth(MsoSubsystems.OPENSTACK)); - // set RequestDbAdapterAttSvc - rsp.setRequestdbAdapterAttsvc(querySubsystemHealth(MsoSubsystems.REQUESTDBATT)); + List<Endpoint> endpoints = config.getEndpoints().stream().filter(item -> { + if (!enableBpmn && SoSubsystems.BPMN.equals(item.getSubsystem())) { + return false; + } else { + return true; + } + }).collect(Collectors.toList()); + + for (Endpoint endpoint : endpoints) { + rsp.getSubsystems().add(querySubsystemHealth(endpoint)); + } + // set Message rsp.setMessage(String.format("HttpStatus: %s", HttpStatus.SC_OK)); logger.info(rsp.toString()); @@ -149,70 +141,51 @@ public class GlobalHealthcheckHandler { protected HttpEntity<String> buildHttpEntityForRequest() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - headers.set("Content-Type", "application/json"); + headers.set(HttpHeaders.CONTENT_TYPE, "application/json"); + headers.set(HttpHeaders.AUTHORIZATION, msoAuth); HttpEntity<String> entity = new HttpEntity<>("parameters", headers); return entity; } - protected String querySubsystemHealth(MsoSubsystems subsystem) { + protected HealthCheckSubsystem querySubsystemHealth(Endpoint subsystem) { + HealthCheckStatus status = HealthCheckStatus.DOWN; + URI uri = subsystem.getUri(); try { // get port number for the subsystem - String ept = getEndpointUrlForSubsystemEnum(subsystem); - // build final endpoint url - UriBuilder builder = UriBuilder.fromPath(ept).path(actuatorContextPath).path(health); - URI uri = builder.build(); - logger.info("Calculated URL: {}", uri.toString()); + uri = UriBuilder.fromUri(subsystem.getUri()).path(actuatorContextPath).path(HEALTH).build(); + logger.info("Calculated URL: {}", uri); ResponseEntity<SubsystemHealthcheckResponse> result = restTemplate.exchange(uri, HttpMethod.GET, buildHttpEntityForRequest(), SubsystemHealthcheckResponse.class); - return processResponseFromSubsystem(result, subsystem); + status = processResponseFromSubsystem(result, subsystem); + } catch (Exception ex) { logger.error("Exception occured in GlobalHealthcheckHandler.querySubsystemHealth() ", ex); - return HealthcheckStatus.DOWN.toString(); } + + return new HealthCheckSubsystem(subsystem.getSubsystem(), uri, status); } - protected String processResponseFromSubsystem(ResponseEntity<SubsystemHealthcheckResponse> result, - MsoSubsystems subsystem) { + protected HealthCheckStatus processResponseFromSubsystem(ResponseEntity<SubsystemHealthcheckResponse> result, + Endpoint endpoint) { if (result == null || result.getStatusCodeValue() != HttpStatus.SC_OK) { logger.error(String.format("Globalhealthcheck: checking subsystem: %s failed ! result object is: %s", - subsystem, result == null ? "NULL" : result)); - return HealthcheckStatus.DOWN.toString(); + endpoint.getSubsystem(), result == null ? "NULL" : result)); + return HealthCheckStatus.DOWN; } SubsystemHealthcheckResponse body = result.getBody(); String status = body.getStatus(); if ("UP".equalsIgnoreCase(status)) { - return HealthcheckStatus.UP.toString(); + return HealthCheckStatus.UP; } else { - logger.error("{}, query health endpoint did not return UP status!", subsystem); - return HealthcheckStatus.DOWN.toString(); + logger.error("{}, query health endpoint did not return UP status!", endpoint.getSubsystem()); + return HealthCheckStatus.DOWN; } } - - protected String getEndpointUrlForSubsystemEnum(MsoSubsystems subsystem) { - switch (subsystem) { - case SDNC: - return this.endpointSdnc; - case ASDC: - return this.endpointAsdc; - case BPMN: - return this.endpointBpmn; - case CATALOGDB: - return this.endpointCatalogdb; - case OPENSTACK: - return this.endpointOpenstack; - case REQUESTDB: - return this.endpointRequestdb; - case REQUESTDBATT: - return this.endpointRequestdbAttsvc; - default: - return ""; - } - } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheck.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheck.java new file mode 100644 index 0000000000..1899cdd765 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheck.java @@ -0,0 +1,84 @@ +package org.onap.so.apihandlerinfra; + +import java.net.URI; +import javax.ws.rs.core.UriBuilder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties(prefix = "mso.health.enpoints") +public class HealthCheck { + + private Subsystem subsystem; + private URI uri; + private HealthCheckStatus status = HealthCheckStatus.DOWN; + + public HealthCheck() { + + } + + public HealthCheck(String subsystem, String uri) { + this.subsystem = SoSubsystems.valueOf(subsystem.toUpperCase()); + this.uri = UriBuilder.fromUri(uri).build(); + } + + public HealthCheck(Subsystem subsystem, URI uri) { + this.subsystem = subsystem; + this.uri = uri; + } + + public HealthCheck(Subsystem subsystem, URI uri, HealthCheckStatus status) { + this.subsystem = subsystem; + this.uri = uri; + this.status = status; + } + + public Subsystem getSubsystem() { + return subsystem; + } + + public void setSubsystem(Subsystem component) { + this.subsystem = component; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public HealthCheckStatus getStatus() { + return status; + } + + public void setStatus(HealthCheckStatus status) { + this.status = status; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("subsystem", subsystem).append("uri", uri).append("status", status) + .toString(); + } + + @Override + public boolean equals(final Object other) { + if (!(other instanceof HealthCheck)) { + return false; + } + HealthCheck castOther = (HealthCheck) other; + return new EqualsBuilder().append(subsystem, castOther.subsystem).append(uri, castOther.uri) + .append(status, castOther.status).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(subsystem).append(uri).append(status).toHashCode(); + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckConfig.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckConfig.java new file mode 100644 index 0000000000..11fd94bc91 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckConfig.java @@ -0,0 +1,83 @@ +/*- + * ============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.apihandlerinfra; + +import java.net.URI; +import java.util.List; +import javax.validation.constraints.NotNull; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.validation.annotation.Validated; + +@Configuration +@ConfigurationProperties(prefix = "mso.health") +@Validated +public class HealthCheckConfig { + + @NotNull + private List<Endpoint> endpoints; + + public List<Endpoint> getEndpoints() { + return endpoints; + } + + public void setEndpoints(List<Endpoint> endpoints) { + this.endpoints = endpoints; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("endpoints", this.endpoints).toString(); + } + + @Validated + public static class Endpoint { + @NotNull + private Subsystem subsystem; + @NotNull + private URI uri; + + public Endpoint() { + + } + + public Endpoint(Subsystem subsystem, URI uri) { + this.subsystem = subsystem; + this.uri = uri; + } + + public Subsystem getSubsystem() { + return subsystem; + } + + public void setSubsystem(Subsystem subsystem) { + this.subsystem = subsystem; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckConverter.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckConverter.java new file mode 100644 index 0000000000..ed06018e7b --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckConverter.java @@ -0,0 +1,22 @@ +package org.onap.so.apihandlerinfra; + +import java.net.URI; +import javax.ws.rs.core.UriBuilder; +import org.springframework.core.convert.TypeDescriptor; +import org.springframework.stereotype.Component; + +@Component +public class HealthCheckConverter { + + + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + if (sourceType.getType() == String.class && targetType.getType() == Subsystem.class) { + return SoSubsystems.valueOf(((String) source).toUpperCase()); + } else if (sourceType.getType() == String.class && targetType.getType() == URI.class) { + return UriBuilder.fromUri((String) source).build(); + } else { + return source; + } + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckResponse.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckResponse.java new file mode 100644 index 0000000000..5400249c65 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckResponse.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.onap.so.apihandlerinfra; + +import java.util.ArrayList; +import java.util.List; + +public class HealthCheckResponse { + + + private List<HealthCheckSubsystem> subsystems = new ArrayList<>(); + private String message; + + + public List<HealthCheckSubsystem> getSubsystems() { + return subsystems; + } + + public void setSubsystems(List<HealthCheckSubsystem> subsystems) { + this.subsystems = subsystems; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckStatus.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckStatus.java index 077a3c2d60..6b31c1f1ed 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckStatus.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckStatus.java @@ -19,12 +19,12 @@ */ package org.onap.so.apihandlerinfra; -public enum HealthcheckStatus { +public enum HealthCheckStatus { UP("UP"), DOWN("DOWN"); private String status; - private HealthcheckStatus(String status) { + private HealthCheckStatus(String status) { this.status = status; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckSubsystem.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckSubsystem.java new file mode 100644 index 0000000000..e1335b952c --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthCheckSubsystem.java @@ -0,0 +1,40 @@ +package org.onap.so.apihandlerinfra; + +import java.net.URI; + +public class HealthCheckSubsystem { + + private Subsystem subsystem; + private URI uri; + private HealthCheckStatus status; + + public HealthCheckSubsystem(Subsystem subsystem, URI uri, HealthCheckStatus status) { + this.subsystem = subsystem; + this.uri = uri; + this.status = status; + } + + public Subsystem getSubsystem() { + return subsystem; + } + + public void setSubsystem(Subsystem subsystem) { + this.subsystem = subsystem; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public HealthCheckStatus getStatus() { + return status; + } + + public void setStatus(HealthCheckStatus status) { + this.status = status; + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckResponse.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckResponse.java deleted file mode 100644 index fad3dd4055..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckResponse.java +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * ============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.apihandlerinfra; - -import org.apache.commons.lang3.builder.ToStringBuilder; - -public class HealthcheckResponse { - private String apih; - private String bpmn; - private String sdncAdapter; - private String asdcController; - private String catalogdbAdapter; - private String requestdbAdapter; - private String openstackAdapter; - private String requestdbAdapterAttsvc; - private String message = ""; - - public String getApih() { - return apih; - } - - public void setApih(String apih) { - this.apih = apih; - } - - public String getBpmn() { - return bpmn; - } - - public void setBpmn(String bpmn) { - this.bpmn = bpmn; - } - - public String getSdncAdapter() { - return sdncAdapter; - } - - public void setSdncAdapter(String sdncAdapter) { - this.sdncAdapter = sdncAdapter; - } - - public String getAsdcController() { - return asdcController; - } - - public void setAsdcController(String asdcController) { - this.asdcController = asdcController; - } - - public String getCatalogdbAdapter() { - return catalogdbAdapter; - } - - public void setCatalogdbAdapter(String catalogdbAdapter) { - this.catalogdbAdapter = catalogdbAdapter; - } - - public String getRequestdbAdapter() { - return requestdbAdapter; - } - - public void setRequestdbAdapter(String requestdbAdapter) { - this.requestdbAdapter = requestdbAdapter; - } - - public String getOpenstackAdapter() { - return openstackAdapter; - } - - public void setOpenstackAdapter(String openstackAdapter) { - this.openstackAdapter = openstackAdapter; - } - - public String getRequestdbAdapterAttsvc() { - return requestdbAdapterAttsvc; - } - - public void setRequestdbAdapterAttsvc(String requestdbAdapterAttsvc) { - this.requestdbAdapterAttsvc = requestdbAdapterAttsvc; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @Override - public String toString() { - return new ToStringBuilder(this).append("apih", this.apih).append("pbmn", this.bpmn) - .append("sdncAdapter", this.sdncAdapter).append("asdcController", this.asdcController) - .append("catalogdbAdapter", this.catalogdbAdapter).append("requestdbAdapter", this.requestdbAdapter) - .append("openstackAdapter", this.openstackAdapter) - .append("requestdbAdapterAttsvc", this.requestdbAdapterAttsvc).append("message", this.message) - .toString(); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoSubsystems.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SoSubsystems.java index 13f1e52068..5842531dc3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoSubsystems.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SoSubsystems.java @@ -19,18 +19,18 @@ */ package org.onap.so.apihandlerinfra; -public enum MsoSubsystems { +public enum SoSubsystems implements Subsystem { APIH("API Handler"), ASDC("ASDC Controller"), BPMN("BPMN Infra"), CATALOGDB("CatalogDb Adapter"), OPENSTACK("Openstack Adapter"), REQUESTDB("RequestDB Adapter"), - REQUESTDBATT("RequestDB Adapter ATT Svc"), SDNC("SDNC Adapter"); + private String subsystem; - private MsoSubsystems(String subsystem) { + private SoSubsystems(String subsystem) { this.subsystem = subsystem; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Subsystem.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Subsystem.java new file mode 100644 index 0000000000..88626f3168 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Subsystem.java @@ -0,0 +1,5 @@ +package org.onap.so.apihandlerinfra; + +public interface Subsystem { + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java index 216588432b..ef5abe9f74 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/ModelDistributionRequest.java @@ -137,10 +137,8 @@ public class ModelDistributionRequest { se.setMessageId(messageId); se.setText(text); if (variables != null) { - if (variables != null) { - for (String variable : variables) { - se.getVariables().add(variable); - } + for (String variable : variables) { + se.getVariables().add(variable); } } re.setServiceException(se); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandlerTest.java index 928b488f6a..0291cfd2ea 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandlerTest.java @@ -20,70 +20,67 @@ package org.onap.so.apihandlerinfra; -import static org.junit.Assert.assertArrayEquals; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.anyString; import java.net.URI; -import java.util.Collections; -import java.util.List; -import org.springframework.test.util.ReflectionTestUtils; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.json.JSONException; -import org.junit.Rule; import org.junit.Test; -import org.mockito.InjectMocks; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; -import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.onap.so.apihandlerinfra.HealthCheckConfig.Endpoint; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.core.JsonProcessingException; +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {GenericStringConverter.class, HealthCheckConverter.class}, + initializers = {ConfigFileApplicationContextInitializer.class}) +@ActiveProfiles("test") +@EnableConfigurationProperties({HealthCheckConfig.class}) public class GlobalHealthcheckHandlerTest { - @Mock - RestTemplate restTemplate; + @MockBean + private RestTemplate restTemplate; - @Mock - ContainerRequestContext requestContext; + @MockBean + private ContainerRequestContext requestContext; - @InjectMocks - @Spy - GlobalHealthcheckHandler globalhealth; - - @Rule - public MockitoRule mockitoRule = MockitoJUnit.rule(); + @SpyBean + private GlobalHealthcheckHandler globalhealth; @Test public void testQuerySubsystemHealthNullResult() { ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); - ReflectionTestUtils.setField(globalhealth, "endpointBpmn", "http://localhost:8080"); Mockito.when(restTemplate.exchange(ArgumentMatchers.any(URI.class), ArgumentMatchers.any(HttpMethod.class), ArgumentMatchers.<HttpEntity<?>>any(), ArgumentMatchers.<Class<Object>>any())).thenReturn(null); - String result = globalhealth.querySubsystemHealth(MsoSubsystems.BPMN); - System.out.println(result); - assertEquals(HealthcheckStatus.DOWN.toString(), result); + HealthCheckSubsystem result = globalhealth + .querySubsystemHealth(new Endpoint(SoSubsystems.BPMN, UriBuilder.fromPath("http://localhost").build())); + assertEquals(HealthCheckStatus.DOWN, result.getStatus()); } @Test public void testQuerySubsystemHealthNotNullResult() { ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); - ReflectionTestUtils.setField(globalhealth, "endpointAsdc", "http://localhost:8080"); SubsystemHealthcheckResponse subSystemResponse = new SubsystemHealthcheckResponse(); subSystemResponse.setStatus("UP"); @@ -92,20 +89,13 @@ public class GlobalHealthcheckHandlerTest { Mockito.when(restTemplate.exchange(ArgumentMatchers.any(URI.class), ArgumentMatchers.any(HttpMethod.class), ArgumentMatchers.<HttpEntity<?>>any(), ArgumentMatchers.<Class<Object>>any())).thenReturn(r); - String result = globalhealth.querySubsystemHealth(MsoSubsystems.ASDC); - System.out.println(result); - assertEquals(HealthcheckStatus.UP.toString(), result); + HealthCheckSubsystem result = globalhealth + .querySubsystemHealth(new Endpoint(SoSubsystems.ASDC, UriBuilder.fromPath("http://localhost").build())); + assertEquals(HealthCheckStatus.UP, result.getStatus()); } private Response globalHealthcheck(String status) { ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); - ReflectionTestUtils.setField(globalhealth, "endpointAsdc", "http://localhost:8080"); - ReflectionTestUtils.setField(globalhealth, "endpointSdnc", "http://localhost:8081"); - ReflectionTestUtils.setField(globalhealth, "endpointBpmn", "http://localhost:8082"); - ReflectionTestUtils.setField(globalhealth, "endpointCatalogdb", "http://localhost:8083"); - ReflectionTestUtils.setField(globalhealth, "endpointOpenstack", "http://localhost:8084"); - ReflectionTestUtils.setField(globalhealth, "endpointRequestdb", "http://localhost:8085"); - ReflectionTestUtils.setField(globalhealth, "endpointRequestdbAttsvc", "http://localhost:8086"); SubsystemHealthcheckResponse subSystemResponse = new SubsystemHealthcheckResponse(); @@ -116,70 +106,41 @@ public class GlobalHealthcheckHandlerTest { Mockito.when(requestContext.getProperty(anyString())).thenReturn("1234567890"); Response response = globalhealth.globalHealthcheck(true, requestContext); - return response; } @Test - public void globalHealthcheckAllUPTest() throws JSONException { - Response response = globalHealthcheck("UP"); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); - HealthcheckResponse root; - root = (HealthcheckResponse) response.getEntity(); - String apistatus = root.getApih(); - assertTrue(apistatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); - - String bpmnstatus = root.getBpmn(); - assertTrue(bpmnstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); - - String sdncstatus = root.getSdncAdapter(); - assertTrue(sdncstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + public void globalHealthcheckAllUPTest() throws JSONException, JsonProcessingException { - String asdcstatus = root.getAsdcController(); - assertTrue(asdcstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + HealthCheckResponse expected = new HealthCheckResponse(); - String catastatus = root.getCatalogdbAdapter(); - assertTrue(catastatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); - - String reqdbstatus = root.getRequestdbAdapter(); - assertTrue(reqdbstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); - - String openstatus = root.getOpenstackAdapter(); - assertTrue(openstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); + for (Subsystem system : SoSubsystems.values()) { + expected.getSubsystems().add(new HealthCheckSubsystem(system, + UriBuilder.fromUri("http://localhost").build(), HealthCheckStatus.UP)); + } + expected.setMessage("HttpStatus: 200"); + Response response = globalHealthcheck("UP"); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + HealthCheckResponse root; + root = (HealthCheckResponse) response.getEntity(); + assertThat(root, sameBeanAs(expected).ignoring("subsystems.uri").ignoring("subsystems.subsystem")); - String reqdbattstatus = root.getRequestdbAdapterAttsvc(); - assertTrue(reqdbattstatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); } @Test public void globalHealthcheckAllDOWNTest() throws JSONException { + HealthCheckResponse expected = new HealthCheckResponse(); + + for (Subsystem system : SoSubsystems.values()) { + expected.getSubsystems().add(new HealthCheckSubsystem(system, + UriBuilder.fromUri("http://localhost").build(), HealthCheckStatus.DOWN)); + } + expected.setMessage("HttpStatus: 200"); Response response = globalHealthcheck("DOWN"); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); - HealthcheckResponse root; - root = (HealthcheckResponse) response.getEntity(); - String apistatus = root.getApih(); - assertTrue(apistatus.equalsIgnoreCase(HealthcheckStatus.UP.toString())); - - String bpmnstatus = root.getBpmn(); - assertTrue(bpmnstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); - - String sdncstatus = root.getSdncAdapter(); - assertTrue(sdncstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); - - String asdcstatus = root.getAsdcController(); - assertTrue(asdcstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); - - String catastatus = root.getCatalogdbAdapter(); - assertTrue(catastatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); - - String reqdbstatus = root.getRequestdbAdapter(); - assertTrue(reqdbstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); - - String openstatus = root.getOpenstackAdapter(); - assertTrue(openstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); - - String reqdbattstatus = root.getRequestdbAdapterAttsvc(); - assertTrue(reqdbattstatus.equalsIgnoreCase(HealthcheckStatus.DOWN.toString())); + HealthCheckResponse root; + root = (HealthCheckResponse) response.getEntity(); + assertThat(root, sameBeanAs(expected).ignoring("subsystems.uri").ignoring("subsystems.subsystem")); } @Test @@ -189,40 +150,15 @@ public class GlobalHealthcheckHandlerTest { assertEquals(MediaType.APPLICATION_JSON, he.getHeaders().getContentType()); } - @Test - public void getEndpointUrlForSubsystemEnumTest() { - ReflectionTestUtils.setField(globalhealth, "actuatorContextPath", "/manage"); - ReflectionTestUtils.setField(globalhealth, "endpointAsdc", "http://localhost:8080"); - ReflectionTestUtils.setField(globalhealth, "endpointSdnc", "http://localhost:8081"); - ReflectionTestUtils.setField(globalhealth, "endpointBpmn", "http://localhost:8082"); - ReflectionTestUtils.setField(globalhealth, "endpointCatalogdb", "http://localhost:8083"); - ReflectionTestUtils.setField(globalhealth, "endpointOpenstack", "http://localhost:8084"); - ReflectionTestUtils.setField(globalhealth, "endpointRequestdb", "http://localhost:8085"); - ReflectionTestUtils.setField(globalhealth, "endpointRequestdbAttsvc", "http://localhost:8086"); - - String result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.ASDC); - assertEquals("http://localhost:8080", result); - result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.SDNC); - assertEquals("http://localhost:8081", result); - result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.BPMN); - assertEquals("http://localhost:8082", result); - result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.CATALOGDB); - assertEquals("http://localhost:8083", result); - result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.OPENSTACK); - assertEquals("http://localhost:8084", result); - result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.REQUESTDB); - assertEquals("http://localhost:8085", result); - result = globalhealth.getEndpointUrlForSubsystemEnum(MsoSubsystems.REQUESTDBATT); - assertEquals("http://localhost:8086", result); - } @Test public void processResponseFromSubsystemTest() { SubsystemHealthcheckResponse subSystemResponse = new SubsystemHealthcheckResponse(); subSystemResponse.setStatus("UP"); ResponseEntity<SubsystemHealthcheckResponse> r = new ResponseEntity<>(subSystemResponse, HttpStatus.OK); - String result = globalhealth.processResponseFromSubsystem(r, MsoSubsystems.BPMN); - assertEquals("UP", result); + Endpoint endpoint = new Endpoint(SoSubsystems.BPMN, UriBuilder.fromUri("http://localhost").build()); + HealthCheckStatus result = globalhealth.processResponseFromSubsystem(r, endpoint); + assertEquals(HealthCheckStatus.UP, result); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml index 2e1c6a9bdc..27e1ae90d2 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml @@ -9,14 +9,20 @@ server: mso: health: endpoints: - catalogdb: http://localhost:${wiremock.server.port} - requestdb: http://localhost:${wiremock.server.port} - sdnc: http://localhost:${wiremock.server.port} - openstack: http://localhost:${wiremock.server.port} - bpmn: http://localhost:${wiremock.server.port} - asdc: http://localhost:${wiremock.server.port} - requestdbattsvc: http://localhost:${wiremock.server.port} - + - subsystem: apih + uri: http://localhost:${wiremock.server.port} + - subsystem: asdc + uri: http://localhost:${wiremock.server.port} + - subsystem: bpmn + uri: http://localhost:${wiremock.server.port} + - subsystem: catalogdb + uri: http://localhost:${wiremock.server.port} + - subsystem: openstack + uri: http://localhost:${wiremock.server.port} + - subsystem: requestdb + uri: http://localhost:${wiremock.server.port} + - subsystem: sdnc + uri: http://localhost:${wiremock.server.port} infra-requests: archived: period: 180 @@ -118,7 +124,13 @@ mariaDB4j: port: 3307 databaseName: catalogdb databaseName2: requestdb - +#Actuator +management: + endpoints: + web: + base-path: /manage + exposure: + include: "*" org: onap: |