From 5363b2782d906a6c6067eb840392f959ed4dfe4b Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 18 Jul 2017 20:23:07 -0400 Subject: [CCSDK-6] Populate seed code Add seed code for sli/adaptors repository Update code to use org.onap.ccsdk.sli.core Change-Id: I477c7a24f2cc1fed8fb0975fe9f33733411c27f9 Signed-off-by: Dan Timoney --- .../org/openecomp/sdnc/ra/ReleaseRequestType.java | 45 + .../org/openecomp/sdnc/ra/ReserveRequestType.java | 43 + .../org/openecomp/sdnc/ra/ResourceAllocator.java | 1016 ++++++++++++++++++++ .../sdnc/ra/alloc/AffinityAllocationRule.java | 68 ++ .../openecomp/sdnc/ra/alloc/DbAllocationRule.java | 155 +++ .../sdnc/ra/alloc/ServingSiteAllocationRule.java | 80 ++ .../openecomp/sdnc/ra/alloc/VrfAllocationRule.java | 111 +++ .../sdnc/ra/check/AnyVrfPresentCheck.java | 74 ++ .../openecomp/sdnc/ra/check/ExcludeVpeCheck.java | 57 ++ .../openecomp/sdnc/ra/check/HubWithRgCheck.java | 107 +++ .../org/openecomp/sdnc/ra/check/OneMVrfCheck.java | 100 ++ .../openecomp/sdnc/ra/check/ProvStatusCheck.java | 49 + .../openecomp/sdnc/ra/check/VlanSpeedCheck.java | 50 + .../org/openecomp/sdnc/ra/check/VpeLockCheck.java | 111 +++ .../org/openecomp/sdnc/ra/comp/AllocationRule.java | 37 + .../sdnc/ra/comp/EndPointAllocationDefinition.java | 60 ++ .../openecomp/sdnc/ra/comp/EndPointAllocator.java | 35 + .../sdnc/ra/comp/EndPointAllocatorImpl.java | 214 +++++ .../org/openecomp/sdnc/ra/comp/EndPointData.java | 33 + .../org/openecomp/sdnc/ra/comp/EquipmentCheck.java | 35 + .../org/openecomp/sdnc/ra/comp/PreferenceRule.java | 30 + .../org/openecomp/sdnc/ra/comp/ServiceData.java | 36 + .../sdnc/ra/equip/comp/EquipmentReader.java | 32 + .../org/openecomp/sdnc/ra/equip/dao/ServerDao.java | 30 + .../openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java | 64 ++ .../openecomp/sdnc/ra/equip/dao/VpePortDao.java | 32 + .../sdnc/ra/equip/dao/VpePortDaoImpl.java | 81 ++ .../openecomp/sdnc/ra/equip/dao/VplspePortDao.java | 30 + .../sdnc/ra/equip/dao/VplspePortDaoImpl.java | 70 ++ .../sdnc/ra/equip/data/EquipmentData.java | 31 + .../sdnc/ra/equip/data/EquipmentLevel.java | 26 + .../openecomp/sdnc/ra/pref/AffinityLinkPref.java | 85 ++ .../openecomp/sdnc/ra/pref/EvcExistingVrfPref.java | 60 ++ .../openecomp/sdnc/ra/reader/AicSiteReader.java | 49 + .../sdnc/ra/reader/UplinkCircuitReader.java | 54 ++ .../org/openecomp/sdnc/ra/reader/VnfReader.java | 49 + .../openecomp/sdnc/ra/reader/VpePortReader.java | 70 ++ .../ra/rule/comp/AllocationRequestBuilder.java | 42 + .../ra/rule/comp/AllocationRequestBuilderImpl.java | 172 ++++ .../sdnc/ra/rule/dao/MaxPortSpeedDao.java | 28 + .../sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java | 85 ++ .../sdnc/ra/rule/dao/MaxServerSpeedDao.java | 28 + .../sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java | 86 ++ .../openecomp/sdnc/ra/rule/dao/ParameterDao.java | 27 + .../sdnc/ra/rule/dao/ParameterDaoImpl.java | 57 ++ .../openecomp/sdnc/ra/rule/dao/RangeRuleDao.java | 32 + .../sdnc/ra/rule/dao/RangeRuleDaoImpl.java | 70 ++ .../sdnc/ra/rule/dao/ResourceRuleDao.java | 38 + .../sdnc/ra/rule/dao/ResourceRuleDaoImpl.java | 117 +++ .../org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java | 27 + .../openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java | 48 + .../org/openecomp/sdnc/ra/rule/data/RangeRule.java | 33 + .../openecomp/sdnc/ra/rule/data/ResourceRule.java | 39 + .../sdnc/ra/rule/data/ResourceThreshold.java | 28 + .../sdnc/ra/rule/data/ThresholdStatus.java | 32 + .../sdnc/ra/service/dao/ServiceResourceDao.java | 38 + .../ra/service/dao/ServiceResourceDaoImpl.java | 110 +++ .../sdnc/ra/service/data/ServiceResource.java | 32 + .../sdnc/ra/service/data/ServiceStatus.java | 27 + 59 files changed, 4505 insertions(+) create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java create mode 100644 resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java (limited to 'resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra') diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java new file mode 100644 index 00000000..52104ec5 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra; + +public enum ReleaseRequestType { + Cancel, Activate, Disconnect; + + public static ReleaseRequestType convert(Object o) { + if (o == null) + return null; + String s = o.toString(); + s = s.trim(); + if (s.length() == 0) + return null; + + if (s.equalsIgnoreCase("Cancel")) + return Cancel; + if (s.equalsIgnoreCase("Activate")) + return Activate; + if (s.equalsIgnoreCase("Disconnect")) + return Disconnect; + + throw new IllegalArgumentException("Invalid request-type: " + s + + ". Supported values are Cancel, Activate, Disconnect."); + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java new file mode 100644 index 00000000..d9964331 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra; + +public enum ReserveRequestType { + New, Change; + + public static ReserveRequestType convert(Object o) { + if (o == null) + return null; + String s = o.toString(); + s = s.trim(); + if (s.length() == 0) + return null; + + if (s.equalsIgnoreCase("New")) + return New; + if (s.equalsIgnoreCase("Change")) + return Change; + + throw new IllegalArgumentException("Invalid request-type: " + s + + ". Supported values are New, Change."); + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java new file mode 100644 index 00000000..ae281cf1 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java @@ -0,0 +1,1016 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.openecomp.sdnc.ra.comp.EndPointAllocator; +import org.openecomp.sdnc.ra.comp.EndPointData; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.dao.ServerDao; +import org.openecomp.sdnc.ra.equip.dao.VpePortDao; +import org.openecomp.sdnc.ra.equip.dao.VplspePortDao; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; +import org.openecomp.sdnc.ra.rule.comp.AllocationRequestBuilder; +import org.openecomp.sdnc.ra.rule.dao.MaxPortSpeedDao; +import org.openecomp.sdnc.ra.rule.dao.MaxServerSpeedDao; +import org.openecomp.sdnc.ra.rule.dao.ParameterDao; +import org.openecomp.sdnc.ra.rule.data.ThresholdStatus; +import org.openecomp.sdnc.ra.service.dao.ServiceResourceDao; +import org.openecomp.sdnc.ra.service.data.ServiceResource; +import org.openecomp.sdnc.ra.service.data.ServiceStatus; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.AllocationAction; +import org.openecomp.sdnc.rm.data.AllocationItem; +import org.openecomp.sdnc.rm.data.AllocationOutcome; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.AllocationStatus; +import org.openecomp.sdnc.rm.data.LimitAllocationOutcome; +import org.openecomp.sdnc.rm.data.LimitAllocationRequest; +import org.openecomp.sdnc.rm.data.LimitResource; +import org.openecomp.sdnc.rm.data.MultiResourceAllocationOutcome; +import org.openecomp.sdnc.rm.data.RangeAllocationItem; +import org.openecomp.sdnc.rm.data.RangeResource; +import org.openecomp.sdnc.rm.data.Resource; +import org.openecomp.sdnc.util.speed.SpeedUtil; +import org.openecomp.sdnc.util.str.StrUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ResourceAllocator implements SvcLogicResource { + + private static final Logger log = LoggerFactory.getLogger(ResourceAllocator.class); + + public ResourceAllocator() { + log.info("ResourceAllocator created."); + } + + private ServerDao serverDao; + private VpePortDao vpePortDao; + private VplspePortDao vplspePortDao; + private MaxPortSpeedDao maxPortSpeedDao; + private MaxServerSpeedDao maxServerSpeedDao; + private ServiceResourceDao serviceResourceDao; + private ParameterDao parameterDao; + + private AllocationRequestBuilder allocationRequestBuilder; + private ResourceManager resourceManager; + private SpeedUtil speedUtil; + + private EndPointAllocator endPointAllocator; + + @Override + public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) + throws SvcLogicException { + return (QueryStatus.SUCCESS); + } + + @Override + public QueryStatus update( + String resource, + String key, + Map parms, + String prefix, + SvcLogicContext ctx) throws SvcLogicException { + + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus save( + String arg0, + boolean arg1, + boolean arg2, + String arg3, + Map arg4, + String arg5, + SvcLogicContext arg6) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + String serviceModel = ctx.getAttribute("tmp.resource-allocator.service-model"); + if (serviceModel != null && serviceModel.trim().length() > 0) + return allocateResources(serviceModel, ctx, true, prefix); + return allocateResourcesL3SDN(ctx, true, prefix); + } + + @Override + public QueryStatus query( + String resource, + boolean localOnly, + String select, + String key, + String prefix, + String orderBy, + SvcLogicContext ctx) throws SvcLogicException { + + prefix = prefix == null ? "" : prefix + '.'; + + if (!resource.equals("NetworkCapacity")) { + log.info("resource: " + resource); + log.info("key: " + key); + + Resource r = resourceManager.getResource(resource, key); + if (r == null) + return QueryStatus.NOT_FOUND; + + if (r instanceof LimitResource) { + ctx.setAttribute(prefix + "used", String.valueOf(((LimitResource) r).used)); + + log.info("Added context attr: " + prefix + "used: " + String.valueOf(((LimitResource) r).used)); + } + + return QueryStatus.SUCCESS; + } + + log.info("key: " + key); + log.info("prefix: " + prefix); + + if (key == null) + return QueryStatus.SUCCESS; + + if (key.startsWith("'") && key.endsWith("'")) + key = key.substring(1, key.length() - 1); + + String endPointPosition = "VPE-Cust"; + + String resourceUnionId = key + '/' + endPointPosition; + List rlist = resourceManager.getResourceUnion(resourceUnionId); + + log.info("Resources found for " + resourceUnionId + ": " + rlist.size()); + + String assetId = null; + for (Resource r : rlist) { + log.info("Resource: " + r.resourceKey.resourceName); + + if (r instanceof RangeResource) { + RangeResource rr = (RangeResource) r; + for (AllocationItem ai : r.allocationItems) + if (ai.resourceUnionId.equals(resourceUnionId)) { + RangeAllocationItem rai = (RangeAllocationItem) ai; + ctx.setAttribute(prefix + r.resourceKey.resourceName, String.valueOf(rai.used.first())); + + log.info("Added context attr: " + prefix + r.resourceKey.resourceName + ": " + + String.valueOf(rr.used.first())); + + assetId = r.resourceKey.assetId; + String vpeName = assetId; + int i1 = assetId.indexOf('/'); + if (i1 > 0) + vpeName = assetId.substring(0, i1); + ctx.setAttribute(prefix + "vpe-name", vpeName); + + log.info("Added context attr: " + prefix + "vpe-name: " + vpeName); + } + } + } + + String affinityLink = "1"; + if (assetId != null) { + for (Resource r : rlist) { + if (r instanceof LimitResource) { + LimitResource ll = (LimitResource) r; + if (ll.resourceKey.assetId.startsWith(assetId + '-')) { + int i1 = ll.resourceKey.assetId.lastIndexOf('-'); + affinityLink = ll.resourceKey.assetId.substring(i1 + 1); + break; + } + } + } + } + + ctx.setAttribute(prefix + "affinity-link", affinityLink); + + log.info("Added context attr: " + prefix + "affinity-link: " + affinityLink); + + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx) + throws SvcLogicException { + String serviceModel = ctx.getAttribute("tmp.resource-allocator.service-model"); + if (serviceModel != null && serviceModel.trim().length() > 0) + return allocateResources(serviceModel, ctx, false, prefix); + return allocateResourcesL3SDN(ctx, false, prefix); + } + + @Override + public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException { + String serviceInstanceId = ctx.getAttribute("tmp.resource-allocator.service-instance-id"); + if (serviceInstanceId == null) + throw new SvcLogicException("tmp.resource-allocator.service-instance-id is required in ResourceAllocator"); + + String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type"); + if (requestTypeStr == null) + throw new SvcLogicException("tmp.resource-allocator.request-type is required in ResourceAllocator"); + + ReleaseRequestType requestType = null; + try { + requestType = ReleaseRequestType.convert(requestTypeStr); + } catch (IllegalArgumentException e) { + throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr + + ". Supported values are Cancel, Activate, Disconnect."); + } + + log.info("Starting release: " + requestType + " for: " + serviceInstanceId); + + ServiceResource activeServiceResource = + serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active); + ServiceResource pendingServiceResource = + serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending); + + log.info("Active ServiceResource: "); + StrUtil.info(log, activeServiceResource); + log.info("Pending ServiceResource: "); + StrUtil.info(log, pendingServiceResource); + + if (requestType == ReleaseRequestType.Cancel) { + if (pendingServiceResource != null) { + log.info("Releasing pending resources: " + pendingServiceResource.resourceSetId); + + resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId); + serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Pending); + } else { + log.info("Pending record not found for service instance: " + serviceInstanceId + ". Nothing to do."); + } + + } else if (requestType == ReleaseRequestType.Activate) { + if (pendingServiceResource != null) { + if (activeServiceResource != null) { + log.info("Releasing active resources: " + activeServiceResource.resourceSetId); + + resourceManager.releaseResourceSet(activeServiceResource.resourceSetId); + serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Active); + } + + log.info("Updating the status of the pending record to active."); + + serviceResourceDao.updateServiceStatus(serviceInstanceId, ServiceStatus.Pending, ServiceStatus.Active); + } else { + log.info("Pending record not found for service instance: " + serviceInstanceId + ". Nothing to do."); + } + + } else if (requestType == ReleaseRequestType.Disconnect) { + if (pendingServiceResource != null) { + log.info("Releasing pending resources: " + pendingServiceResource.resourceSetId); + + resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId); + serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Pending); + } + if (activeServiceResource != null) { + log.info("Releasing active resources: " + activeServiceResource.resourceSetId); + + resourceManager.releaseResourceSet(activeServiceResource.resourceSetId); + serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Active); + } + } + + return QueryStatus.SUCCESS; + } + + private QueryStatus allocateResourcesL3SDN(SvcLogicContext ctx, boolean checkOnly, String prefix) + throws SvcLogicException { + prefix = prefix == null ? "" : prefix + '.'; + + String aicSiteId = getAicSiteId(ctx); + Map service = getServiceData(ctx); + + String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type"); + if (requestTypeStr == null) + requestTypeStr = "New"; + + ReserveRequestType requestType = null; + try { + requestType = ReserveRequestType.convert(requestTypeStr); + } catch (IllegalArgumentException e) { + throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr + + ". Supported values are New, Change."); + } + + String serviceInstanceId = String.valueOf(service.get("service-instance-id")); + + ServiceResource activeServiceResource = + serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active); + ServiceResource pendingServiceResource = + serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending); + + log.info("Active ServiceResource: "); + StrUtil.info(log, activeServiceResource); + log.info("Pending ServiceResource: "); + StrUtil.info(log, pendingServiceResource); + + ServiceResource sr = new ServiceResource(); + sr.serviceInstanceId = serviceInstanceId; + sr.serviceStatus = ServiceStatus.Pending; + sr.serviceChangeNumber = 1; + if (pendingServiceResource != null) + sr.serviceChangeNumber = pendingServiceResource.serviceChangeNumber + 1; + else if (activeServiceResource != null) + sr.serviceChangeNumber = activeServiceResource.serviceChangeNumber + 1; + sr.resourceSetId = serviceInstanceId + "/" + sr.serviceChangeNumber; + sr.resourceUnionId = serviceInstanceId; + + log.info("New ServiceResource: "); + StrUtil.info(log, sr); + + List> vpePortData = vpePortDao.getVpePortData(aicSiteId); + List> vplspePortData = vplspePortDao.getVplspePortData(aicSiteId); + List> serverData = serverDao.getServerData(aicSiteId); + + vpePortData = orderVpe(vpePortData); + + long maxAvailableSpeedVpePort = 0; + boolean vpePortFound = false; + + for (Map vpe : vpePortData) { + String vpeId = String.valueOf(vpe.get("vpe-id")); + String interfaceName = String.valueOf(vpe.get("physical-interface-name")); + String portId = vpeId + "/" + interfaceName; + + log.info("Checking VPE port: " + portId); + + String provStatus = String.valueOf(vpe.get("provisioning-status")); + if (!provStatus.equals("PROV")) { + log.info("Skipping port " + portId + ": Provisioning status is not PROV."); + continue; + } + + String imageFile = String.valueOf(vpe.get("image-file-name")); + String endPointPosition = "VPE-Cust"; + long maxPortSpeed = maxPortSpeedDao.getMaxPortSpeed(imageFile, endPointPosition, interfaceName); + vpe.put("max-port-speed", maxPortSpeed); + + EquipmentData ed = new EquipmentData(); + ed.data = vpe; + ed.equipmentId = portId; + ed.equipmentLevel = EquipmentLevel.Port; + + ServiceData sd = new ServiceData(); + sd.data = service; + sd.serviceModel = "L3SDN"; + sd.endPointPosition = endPointPosition; + sd.resourceUnionId = sr.resourceUnionId; + sd.resourceSetId = sr.resourceSetId; + + StrUtil.info(log, ed); + StrUtil.info(log, sd); + + AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly, + requestType == ReserveRequestType.Change); + AllocationOutcome ao = resourceManager.allocateResources(ar); + + if (ao.status == AllocationStatus.Success) { + + // Assign affinity link + if (!checkOnly) { + List affinityLinkIdList = new ArrayList<>(); + affinityLinkIdList.add("0"); + affinityLinkIdList.add("1"); + affinityLinkIdList.add("2"); + affinityLinkIdList.add("3"); + + String preferedAffinityLinkId = "0"; + long lowestAssignedBw = Long.MAX_VALUE; + for (String affinityLinkId : affinityLinkIdList) { + long used = 0; + String assetId = ed.equipmentId + "-" + affinityLinkId; + Resource r = resourceManager.getResource("Bandwidth", assetId); + if (r != null) { + LimitResource ll = (LimitResource) r; + used = ll.used; + } + if (used < lowestAssignedBw) { + lowestAssignedBw = used; + preferedAffinityLinkId = affinityLinkId; + } + log.info("Assigned bandwidth on affinity link: " + assetId + ": " + used); + } + + log.info("Prefered affinity link for " + ed.equipmentId + ": " + preferedAffinityLinkId); + + ctx.setAttribute(prefix + "affinity-link", preferedAffinityLinkId); + + LimitAllocationRequest ar1 = new LimitAllocationRequest(); + ar1.resourceSetId = sd.resourceSetId; + ar1.resourceUnionId = sd.resourceUnionId; + ar1.resourceShareGroupList = null; + ar1.resourceName = "Bandwidth"; + ar1.assetId = ed.equipmentId + "-" + preferedAffinityLinkId; + ar1.missingResourceAction = AllocationAction.Succeed_Allocate; + ar1.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar1.replace = true; + ar1.strict = false; + ar1.checkLimit = Long.MAX_VALUE; + ar1.checkCount = 0; + ar1.allocateCount = (Long) sd.data.get("service-speed-kbps"); + + resourceManager.allocateResources(ar1); + } + + ctx.setAttribute(prefix + "vpe-name", vpeId); + + vpePortFound = true; + break; + } + + if (ao instanceof LimitAllocationOutcome) { + LimitAllocationOutcome lao = (LimitAllocationOutcome) ao; + long available = lao.limit - lao.used; + if (available > maxAvailableSpeedVpePort) + maxAvailableSpeedVpePort = available; + } + } + + long maxAvailableSpeedVplspePort = 0; + boolean vplspePortFound = false; + + for (Map vplspe : vplspePortData) { + String vplspeId = String.valueOf(vplspe.get("vplspe-id")); + String interfaceName = String.valueOf(vplspe.get("physical-interface-name")); + String portId = vplspeId + "/" + interfaceName; + + log.info("Checking VPLSPE port: " + portId); + + String provStatus = String.valueOf(vplspe.get("provisioning-status")); + if (!provStatus.equals("PROV")) { + log.info("Skipping port " + portId + ": Provisioning status is not PROV."); + continue; + } + + long physicalSpeed = (Long) vplspe.get("physical-interface-speed"); + String physicalSpeedUnit = String.valueOf(vplspe.get("physical-interface-speed-unit")); + long maxPortSpeed = speedUtil.convertToKbps(physicalSpeed, physicalSpeedUnit); + vplspe.put("max-port-speed", maxPortSpeed); + + EquipmentData ed = new EquipmentData(); + ed.data = vplspe; + ed.equipmentId = portId; + ed.equipmentLevel = EquipmentLevel.Port; + + ServiceData sd = new ServiceData(); + sd.data = service; + sd.serviceModel = "L3SDN"; + sd.endPointPosition = "IPAG-TOA"; + sd.resourceUnionId = sr.resourceUnionId; + sd.resourceSetId = sr.resourceSetId; + + StrUtil.info(log, ed); + StrUtil.info(log, sd); + + AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly, + requestType == ReserveRequestType.Change); + AllocationOutcome ao = resourceManager.allocateResources(ar); + + if (ao.status == AllocationStatus.Success) { + vplspePortFound = true; + break; + } + + if (ao instanceof LimitAllocationOutcome) { + LimitAllocationOutcome lao = (LimitAllocationOutcome) ao; + long available = lao.limit - lao.used; + if (available > maxAvailableSpeedVplspePort) + maxAvailableSpeedVplspePort = available; + } + } + + long maxAvailableSpeedServer = 0; + boolean serverFound = false; + + for (Map server : serverData) { + String serverId = String.valueOf(server.get("server-id")); + String serverModel = String.valueOf(server.get("server-model")); + + log.info("Checking Server: " + serverId); + + String endPointPosition = "VCE-Cust"; + + int serverCount = (Integer) server.get("server-count"); + if (serverCount == 0) + serverCount = 1; + String ratioString = parameterDao.getParameter("homing.pserver.sparing.ratio"); + if (ratioString == null || ratioString.length() == 0) + ratioString = "1:1"; + int primaryServerCount = calculatePrimaryServerCount(serverCount, ratioString); + server.put("number-primary-servers", primaryServerCount); + + int evcCount = getEvcCountOnServer(serverId); + int evcCountPerServer = (evcCount + primaryServerCount - 1) / primaryServerCount; + long maxServerSpeed = maxServerSpeedDao.getMaxServerSpeed(serverModel, evcCountPerServer); + server.put("max-server-speed", maxServerSpeed); + server.put("evc-count", evcCount); + server.put("evc-count-per-server", evcCountPerServer); + + EquipmentData ed = new EquipmentData(); + ed.data = server; + ed.equipmentId = serverId; + ed.equipmentLevel = EquipmentLevel.Server; + + ServiceData sd = new ServiceData(); + sd.data = service; + sd.serviceModel = "L3SDN"; + sd.endPointPosition = endPointPosition; + sd.resourceUnionId = sr.resourceUnionId; + sd.resourceSetId = sr.resourceSetId; + + StrUtil.info(log, ed); + StrUtil.info(log, sd); + + AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly, + requestType == ReserveRequestType.Change); + AllocationOutcome ao = resourceManager.allocateResources(ar); + + if (ao.status == AllocationStatus.Success) { + serverFound = true; + + if (ao instanceof MultiResourceAllocationOutcome) { + MultiResourceAllocationOutcome mrao = (MultiResourceAllocationOutcome) ao; + for (AllocationOutcome ao1 : mrao.allocationOutcomeList) { + if (ao1 instanceof LimitAllocationOutcome) { + LimitAllocationOutcome lao = (LimitAllocationOutcome) ao1; + if (lao.request.resourceName.equals("Bandwidth")) { + ThresholdStatus th = allocationRequestBuilder.getThresholdStatus(sd, ed, lao); + setThresholdData(ctx, th, sd, ed); + } + } + } + } + + break; + } + + if (ao instanceof MultiResourceAllocationOutcome) { + MultiResourceAllocationOutcome mrao = (MultiResourceAllocationOutcome) ao; + for (AllocationOutcome ao1 : mrao.allocationOutcomeList) { + if (ao1 instanceof LimitAllocationOutcome) { + LimitAllocationOutcome lao = (LimitAllocationOutcome) ao1; + if (lao.status == AllocationStatus.Failure && lao.request.resourceName.equals("Bandwidth")) { + long available = lao.limit - lao.used; + if (available > maxAvailableSpeedServer) + maxAvailableSpeedServer = available; + } + if (lao.status == AllocationStatus.Failure && lao.request.resourceName.equals("Connection")) { + maxAvailableSpeedServer = 0; + break; + } + + ThresholdStatus th = allocationRequestBuilder.getThresholdStatus(sd, ed, lao); + setThresholdData(ctx, th, sd, ed); + } + } + } + } + + if (vpePortFound && vplspePortFound && serverFound) { + if (!checkOnly) { + if (pendingServiceResource == null) { + log.info("Adding the pending service resource record to DB."); + serviceResourceDao.addServiceResource(sr); + } else { + log.info("Releasing previously allocated resources for resource set id: " + + pendingServiceResource.resourceSetId); + resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId); + + log.info("Updating the pending service resource record in DB with service change number: " + + sr.serviceChangeNumber); + serviceResourceDao.updateServiceResource(sr); + } + } + + return QueryStatus.SUCCESS; + } + + log.info("Releasing allocated resources (if any) for resource set id: " + sr.resourceSetId); + resourceManager.releaseResourceSet(sr.resourceSetId); + + long maxAvailableSpeed = Long.MAX_VALUE; + if (!vpePortFound && maxAvailableSpeedVpePort < maxAvailableSpeed) + maxAvailableSpeed = maxAvailableSpeedVpePort; + if (!vplspePortFound && maxAvailableSpeedVplspePort < maxAvailableSpeed) + maxAvailableSpeed = maxAvailableSpeedVplspePort; + if (!serverFound && maxAvailableSpeedServer < maxAvailableSpeed) + maxAvailableSpeed = maxAvailableSpeedServer; + + setOutputContext(ctx, maxAvailableSpeed, "kbps"); + return QueryStatus.NOT_FOUND; + } + + private List> orderVpe(List> vpePortData) { + for (Map vpe : vpePortData) { + String vpeId = String.valueOf(vpe.get("vpe-id")); + String interfaceName = String.valueOf(vpe.get("physical-interface-name")); + String portId = vpeId + "/" + interfaceName; + Resource r = resourceManager.getResource("Bandwidth", portId); + long used = 0; + if (r != null) { + LimitResource ll = (LimitResource) r; + used = ll.used; + } + vpe.put("used-bandwidth", used); + + log.info("Used bandwidth on VPE: " + vpeId + ": " + used); + } + + Collections.sort(vpePortData, new Comparator>() { + + @Override + public int compare(Map o1, Map o2) { + long used1 = (Long) o1.get("used-bandwidth"); + long used2 = (Long) o2.get("used-bandwidth"); + if (used1 < used2) + return -1; + if (used1 > used2) + return 1; + return 0; + } + }); + + return vpePortData; + } + + private void setThresholdData(SvcLogicContext ctx, ThresholdStatus th, ServiceData sd, EquipmentData ed) { + if (th == null) + return; + + String pp = "tmp.resource-allocator-output.threshold-notification-list.threshold-hotification[0]."; + ctx.setAttribute("tmp.resource-allocator-output.threshold-notification-list.threshold-hotification_length", + "1"); + ctx.setAttribute(pp + "message", th.resourceThreshold.message); + ctx.setAttribute(pp + "resource-rule.service-model", th.resourceRule.serviceModel); + ctx.setAttribute(pp + "resource-rule.endpoint-position", th.resourceRule.endPointPosition); + ctx.setAttribute(pp + "resource-rule.resource-name", th.resourceRule.resourceName); + ctx.setAttribute(pp + "resource-rule.equipment-level", th.resourceRule.equipmentLevel); + ctx.setAttribute(pp + "resource-rule.soft-limit-expression", th.resourceRule.softLimitExpression); + ctx.setAttribute(pp + "resource-rule.hard-limit-expression", th.resourceRule.hardLimitExpression); + ctx.setAttribute(pp + "resource-state.used", String.valueOf(th.used)); + ctx.setAttribute(pp + "resource-state.limit-value", String.valueOf(th.limitValue)); + ctx.setAttribute(pp + "resource-state.threshold-value", String.valueOf(th.thresholdValue)); + ctx.setAttribute(pp + "resource-state.last-added", String.valueOf(th.lastAdded)); + ctx.setAttribute(pp + "equipment-data.equipment-id", ed.equipmentId); + for (String edKey : ed.data.keySet()) + ctx.setAttribute(pp + "equipment-data." + edKey, String.valueOf(ed.data.get(edKey))); + } + + private QueryStatus allocateResources(String serviceModel, SvcLogicContext ctx, boolean checkOnly, String prefix) + throws SvcLogicException { + prefix = prefix == null ? "" : prefix + '.'; + + Map service = getServiceData(ctx); + Map ec = getEquipConstraints(ctx); + + String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type"); + if (requestTypeStr == null) + requestTypeStr = "New"; + + ReserveRequestType requestType = null; + try { + requestType = ReserveRequestType.convert(requestTypeStr); + } catch (IllegalArgumentException e) { + throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr + + ". Supported values are New, Change."); + } + + String serviceInstanceId = String.valueOf(service.get("service-instance-id")); + + log.info("Starting reserve: " + requestType + ", service-instance-id: " + serviceInstanceId); + + ServiceResource activeServiceResource = + serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active); + ServiceResource pendingServiceResource = + serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending); + + log.info("Active ServiceResource: "); + StrUtil.info(log, activeServiceResource); + log.info("Pending ServiceResource: "); + StrUtil.info(log, pendingServiceResource); + + int changeNumber = 1; + if (pendingServiceResource != null) + changeNumber = pendingServiceResource.serviceChangeNumber + 1; + else if (activeServiceResource != null) + changeNumber = activeServiceResource.serviceChangeNumber + 1; + + ServiceData sd = new ServiceData(); + sd.data = service; + sd.serviceModel = serviceModel; + sd.endPointPosition = (String) service.get("end-point-position"); + sd.resourceShareGroup = (String) service.get("resource-share-group"); + sd.resourceName = (String) service.get("resource-name"); + sd.serviceInstanceId = serviceInstanceId; + + StrUtil.info(log, sd); + + List epList = endPointAllocator.allocateEndPoints(sd, ec, checkOnly, + requestType == ReserveRequestType.Change, changeNumber); + + if (epList != null && !epList.isEmpty()) { + if (!checkOnly) { + EndPointData ep = epList.get(0); + + if (sd.resourceName == null) { + ServiceResource sr = new ServiceResource(); + sr.serviceInstanceId = serviceInstanceId; + sr.serviceStatus = ServiceStatus.Pending; + sr.serviceChangeNumber = changeNumber; + sr.resourceSetId = ep.resourceSetId; + sr.resourceUnionId = ep.resourceUnionId; + + log.info("New ServiceResource: "); + StrUtil.info(log, sr); + + if (pendingServiceResource == null) { + log.info("Adding the pending service resource record to DB."); + serviceResourceDao.addServiceResource(sr); + } else { + log.info("Releasing previously allocated resources for resource set id: " + + pendingServiceResource.resourceSetId); + resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId); + + log.info("Updating the pending service resource record in DB with service change number: " + + sr.serviceChangeNumber); + serviceResourceDao.updateServiceResource(sr); + } + } + + for (EndPointData ep1 : epList) + if (ep1.data != null && !ep1.data.isEmpty()) + for (String key : ep1.data.keySet()) { + String value = String.valueOf(ep1.data.get(key)); + ctx.setAttribute(prefix + key, value); + + log.info("Added context attr: " + prefix + key + ": " + value); + } + } + + return QueryStatus.SUCCESS; + } + + log.info("Capacity not found for EVC: " + serviceInstanceId); + + return QueryStatus.NOT_FOUND; + } + + private int getEvcCountOnServer(String serverId) { + LimitResource l = (LimitResource) resourceManager.getResource("Connection", serverId); + if (l != null) + return (int) l.used; + return 0; + } + + private String getAicSiteId(SvcLogicContext ctx) throws SvcLogicException { + String aicSiteId = ctx.getAttribute("tmp.resource-allocator.aic-site-id"); + if (aicSiteId == null) + throw new SvcLogicException("tmp.resource-allocator.aic-site-id is required in ResourceAllocator"); + return aicSiteId; + } + + private Map getServiceData(SvcLogicContext ctx) throws SvcLogicException { + Map sd = new HashMap(); + + String endPointPosition = ctx.getAttribute("tmp.resource-allocator.end-point-position"); + if (endPointPosition != null && endPointPosition.trim().length() > 0) + sd.put("end-point-position", endPointPosition.trim()); + + String resourceName = ctx.getAttribute("tmp.resource-allocator.resource-name"); + if (resourceName != null && resourceName.trim().length() > 0) + sd.put("resource-name", resourceName.trim()); + + String resourceShareGroup = ctx.getAttribute("tmp.resource-allocator.resource-share-group"); + if (resourceShareGroup != null && resourceShareGroup.trim().length() > 0) + sd.put("resource-share-group", resourceShareGroup.trim()); + + String serviceInstanceId = ctx.getAttribute("tmp.resource-allocator.service-instance-id"); + if (serviceInstanceId == null) + serviceInstanceId = "checkServiceInstance"; + sd.put("service-instance-id", serviceInstanceId); + + String speedStr = ctx.getAttribute("tmp.resource-allocator.speed"); + if (speedStr != null && speedStr.trim().length() > 0) { + long speed = 0; + try { + speed = Long.parseLong(speedStr); + } catch (NumberFormatException e) { + throw new SvcLogicException("Invalid tmp.resource-allocator.speed. Must be a number."); + } + String unit = ctx.getAttribute("tmp.resource-allocator.speed-unit"); + if (unit == null || unit.trim().length() == 0) + throw new SvcLogicException("tmp.resource-allocator.speed-unit is required in ResourceAllocator"); + long serviceSpeedKbps = speedUtil.convertToKbps(speed, unit); + + sd.put("service-speed-kbps", serviceSpeedKbps); + } + + String vpnId = ctx.getAttribute("tmp.resource-allocator.vpn-id"); + if (vpnId != null && vpnId.trim().length() > 0) + sd.put("vpn-id", vpnId.trim()); + + String vpnIdList = ctx.getAttribute("tmp.resource-allocator.vpn-id-list"); + if (vpnIdList != null && vpnIdList.trim().length() > 0) + sd.put("vpn-id-list", vpnIdList.trim()); + + String vrfName = ctx.getAttribute("tmp.resource-allocator.vrf-name"); + if (vrfName != null && vrfName.trim().length() > 0) + sd.put("vrf-name", vrfName.trim()); + + String vrfNameList = ctx.getAttribute("tmp.resource-allocator.vrf-name-list"); + if (vrfNameList != null && vrfNameList.trim().length() > 0) + sd.put("vrf-name-list", vrfNameList.trim()); + + String v4multicast = ctx.getAttribute("tmp.resource-allocator.v4-multicast"); + if (v4multicast != null && v4multicast.trim().length() > 0) + sd.put("v4-multicast", v4multicast.trim()); + + String v6multicast = ctx.getAttribute("tmp.resource-allocator.v6-multicast"); + if (v6multicast != null && v6multicast.trim().length() > 0) + sd.put("v6-multicast", v6multicast.trim()); + + String v4ServingSite = ctx.getAttribute("tmp.resource-allocator.v4-serving-site"); + if (v4ServingSite != null && v4ServingSite.trim().length() > 0) + sd.put("v4-serving-site", v4ServingSite.trim()); + + String v6ServingSite = ctx.getAttribute("tmp.resource-allocator.v6-serving-site"); + if (v6ServingSite != null && v6ServingSite.trim().length() > 0) + sd.put("v6-serving-site", v6ServingSite.trim()); + + return sd; + } + + private Map getEquipConstraints(SvcLogicContext ctx) throws SvcLogicException { + Map mm = new HashMap(); + + String vrfRequired = ctx.getAttribute("tmp.resource-allocator.vrf-required"); + if (vrfRequired != null && vrfRequired.trim().length() > 0) + mm.put("vrf-required", vrfRequired.trim()); + + String clli = ctx.getAttribute("tmp.resource-allocator.clli"); + if (clli == null || clli.trim().length() == 0) + clli = ctx.getAttribute("tmp.resource-allocator.aic-site-id"); + if (clli != null) { + mm.put("clli", clli.trim()); + mm.put("aic-site-id", clli.trim()); + } + + String vpeName = ctx.getAttribute("tmp.resource-allocator.vpe-name"); + if (vpeName != null && vpeName.trim().length() > 0) + mm.put("vpe-name", vpeName.trim()); + + String vnfName = ctx.getAttribute("tmp.resource-allocator.device-name"); + if (vnfName != null && vnfName.trim().length() > 0) + mm.put("vnf-name", vnfName.trim()); + + String excludeVpeList = ctx.getAttribute("tmp.resource-allocator.exclude-vpe-list"); + if (excludeVpeList != null && excludeVpeList.trim().length() > 0) + mm.put("exclude-vpe-list", excludeVpeList.trim()); + + String uplinkCircuitCountStr = + ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit_length"); + if (uplinkCircuitCountStr != null) { + long uplinkCircuitCount = 0; + try { + uplinkCircuitCount = Long.parseLong(uplinkCircuitCountStr); + } catch (NumberFormatException e) { + throw new SvcLogicException( + "Invalid tmp.resource-allocator.uplink-circuit-list.uplink-circuit_length. Must be a number."); + } + List> uplinkCircuitList = new ArrayList<>(); + for (int i = 0; i < uplinkCircuitCount; i++) { + String uplinkCircuitId = ctx.getAttribute( + "tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i + "].uplink-circuit-id"); + String uplinkCircuitBandwidthStr = + ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i + + "].uplink-circuit-bandwidth"); + String uplinkCircuitBandwidthUnit = + ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i + + "].uplink-circuit-bandwidth-unit"); + + long uplinkCircuitBandwidth = 0; + try { + uplinkCircuitBandwidth = Long.parseLong(uplinkCircuitBandwidthStr); + } catch (NumberFormatException e) { + throw new SvcLogicException("Invalid tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + + i + "].uplink-circuit-id. Must be a number."); + } + + long uplinkCircuitBandwidthKbps = + speedUtil.convertToKbps(uplinkCircuitBandwidth, uplinkCircuitBandwidthUnit); + + Map uplinkCircuit = new HashMap(); + uplinkCircuit.put("uplink-circuit-id", uplinkCircuitId); + uplinkCircuit.put("uplink-circuit-bandwidth", uplinkCircuitBandwidthKbps); + uplinkCircuitList.add(uplinkCircuit); + } + mm.put("uplink-circuit-list", uplinkCircuitList); + } + + return mm; + } + + private void setOutputContext(SvcLogicContext ctx, long maxAvailableSpeed, String unit) { + ctx.setAttribute("tmp.resource-allocator-output.max-available-speed", String.valueOf(maxAvailableSpeed)); + ctx.setAttribute("tmp.resource-allocator-output.speed-unit", unit); + } + + private int calculatePrimaryServerCount(int serverCount, String ratioString) throws SvcLogicException { + String[] ss = ratioString.split(":"); + if (ss.length != 2) + throw new SvcLogicException("Invalid value for homing.pserver.sparing.ratio: " + ratioString); + + int n = 1, m = 1; + try { + n = Integer.parseInt(ss[0]); + m = Integer.parseInt(ss[1]); + } catch (Exception e) { + throw new SvcLogicException("Invalid value for homing.pserver.sparing.ratio: " + ratioString); + } + + return (serverCount - 1) * n / (n + m) + 1; + } + + public void setServerDao(ServerDao serverDao) { + this.serverDao = serverDao; + } + + public void setVpePortDao(VpePortDao vpePortDao) { + this.vpePortDao = vpePortDao; + } + + public void setVplspePortDao(VplspePortDao vplspePortDao) { + this.vplspePortDao = vplspePortDao; + } + + public void setMaxPortSpeedDao(MaxPortSpeedDao maxPortSpeedDao) { + this.maxPortSpeedDao = maxPortSpeedDao; + } + + public void setMaxServerSpeedDao(MaxServerSpeedDao maxServerSpeedDao) { + this.maxServerSpeedDao = maxServerSpeedDao; + } + + public void setAllocationRequestBuilder(AllocationRequestBuilder allocationRequestBuilder) { + this.allocationRequestBuilder = allocationRequestBuilder; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } + + public void setSpeedUtil(SpeedUtil speedUtil) { + this.speedUtil = speedUtil; + } + + public void setServiceResourceDao(ServiceResourceDao serviceResourceDao) { + this.serviceResourceDao = serviceResourceDao; + } + + public void setEndPointAllocator(EndPointAllocator endPointAllocator) { + this.endPointAllocator = endPointAllocator; + } + + public void setParameterDao(ParameterDao parameterDao) { + this.parameterDao = parameterDao; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java new file mode 100644 index 00000000..b77df92a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.alloc; + +import org.openecomp.sdnc.ra.comp.AllocationRule; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.data.AllocationAction; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.LimitAllocationRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AffinityAllocationRule implements AllocationRule { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(AffinityAllocationRule.class); + + @Override + public AllocationRequest buildAllocationRequest( + String resourceUnionId, + String resourceSetId, + String endPointPosition, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + String affinityLink = (String) equipmentData.data.get("affinity-link"); + if (affinityLink == null) + affinityLink = "1"; + + long serviceSpeed = (Long) serviceData.data.get("service-speed-kbps"); + + LimitAllocationRequest ar = new LimitAllocationRequest(); + ar.resourceSetId = resourceSetId; + ar.resourceUnionId = resourceUnionId; + ar.resourceShareGroupList = null; + ar.resourceName = "Bandwidth"; + ar.assetId = equipmentData.equipmentId + "-" + affinityLink; + ar.missingResourceAction = AllocationAction.Succeed_Allocate; + ar.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar.replace = true; + ar.strict = false; + ar.checkLimit = Long.MAX_VALUE; + ar.checkCount = 0; + ar.allocateCount = serviceSpeed; + return ar; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java new file mode 100644 index 00000000..a066378a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.alloc; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.openecomp.sdnc.ra.comp.AllocationRule; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.rule.dao.RangeRuleDao; +import org.openecomp.sdnc.ra.rule.dao.ResourceRuleDao; +import org.openecomp.sdnc.ra.rule.data.RangeRule; +import org.openecomp.sdnc.ra.rule.data.ResourceRule; +import org.openecomp.sdnc.rm.data.AllocationAction; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.LimitAllocationRequest; +import org.openecomp.sdnc.rm.data.MultiResourceAllocationRequest; +import org.openecomp.sdnc.rm.data.RangeAllocationRequest; +import org.openecomp.sdnc.util.expr.ExpressionEvaluator; +import org.openecomp.sdnc.util.str.StrUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DbAllocationRule implements AllocationRule { + + private static final Logger log = LoggerFactory.getLogger(DbAllocationRule.class); + + private ResourceRuleDao resourceRuleDao; + private RangeRuleDao rangeRuleDao; + + @Override + public AllocationRequest buildAllocationRequest( + String resourceUnionId, + String resourceSetId, + String endPointPosition, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + List resourceRuleList = resourceRuleDao.getResourceRules(serviceData.serviceModel, + endPointPosition, equipmentData.equipmentLevel); + List rangeRuleList = + rangeRuleDao.getRangeRules(serviceData.serviceModel, endPointPosition, equipmentData.equipmentLevel); + + List arlist = new ArrayList(); + + for (ResourceRule rr : resourceRuleList) { + if (serviceData.resourceName != null && !serviceData.resourceName.equals(rr.resourceName)) + continue; + AllocationRequest ar1 = buildAllocationRequest(rr, resourceUnionId, resourceSetId, serviceData, + equipmentData, checkOnly, change); + arlist.add(ar1); + } + for (RangeRule rr : rangeRuleList) { + if (serviceData.resourceName != null && !serviceData.resourceName.equals(rr.rangeName)) + continue; + AllocationRequest ar1 = buildAllocationRequest(rr, resourceUnionId, resourceSetId, serviceData, + equipmentData, checkOnly, change); + arlist.add(ar1); + } + + if (arlist.isEmpty()) + return null; + + if (arlist.size() == 1) + return arlist.get(0); + + MultiResourceAllocationRequest ar = new MultiResourceAllocationRequest(); + ar.stopOnFirstFailure = false; + ar.allocationRequestList = arlist; + return ar; + } + + private AllocationRequest buildAllocationRequest( + ResourceRule resourceRule, + String resourceUnionId, + String resourceSetId, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + StrUtil.info(log, resourceRule); + + LimitAllocationRequest ar = new LimitAllocationRequest(); + ar.resourceSetId = resourceSetId; + ar.resourceUnionId = resourceUnionId; + ar.resourceName = resourceRule.resourceName; + if (serviceData.resourceShareGroup != null) + ar.resourceShareGroupList = Collections.singleton(serviceData.resourceShareGroup); + ar.assetId = equipmentData.equipmentId; + ar.missingResourceAction = AllocationAction.Succeed_Allocate; + ar.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar.replace = true; + ar.strict = false; + ar.checkLimit = ExpressionEvaluator.evalLong( + change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, equipmentData.data);; + ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, serviceData.data); + ar.allocateCount = checkOnly ? 0 : ar.checkCount; + return ar; + } + + private AllocationRequest buildAllocationRequest( + RangeRule rangeRule, + String resourceUnionId, + String resourceSetId, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + StrUtil.info(log, rangeRule); + + RangeAllocationRequest ar = new RangeAllocationRequest(); + ar.resourceSetId = resourceSetId; + ar.resourceUnionId = resourceUnionId; + ar.resourceName = rangeRule.rangeName; + ar.assetId = equipmentData.equipmentId; + ar.missingResourceAction = AllocationAction.Succeed_Allocate; + ar.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar.replace = true; + ar.check = true; + ar.allocate = !checkOnly; + ar.checkMin = rangeRule.minValue; + ar.checkMax = rangeRule.maxValue; + return ar; + } + + public void setResourceRuleDao(ResourceRuleDao resourceRuleDao) { + this.resourceRuleDao = resourceRuleDao; + } + + public void setRangeRuleDao(RangeRuleDao rangeRuleDao) { + this.rangeRuleDao = rangeRuleDao; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java new file mode 100644 index 00000000..cb36a8be --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.alloc; + +import org.openecomp.sdnc.ra.comp.AllocationRule; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.data.AllocationAction; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.LimitAllocationRequest; +import org.openecomp.sdnc.util.vrf.VpnParam; +import org.openecomp.sdnc.util.vrf.VrfUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServingSiteAllocationRule implements AllocationRule { + + private static final Logger log = LoggerFactory.getLogger(ServingSiteAllocationRule.class); + + @Override + public AllocationRequest buildAllocationRequest( + String resourceUnionId, + String resourceSetId, + String endPointPosition, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + String vrfName = (String) serviceData.data.get("vrf-name"); + if (vrfName == null) + return null; + + log.info("vrfName: " + vrfName); + + String v4ServingSiteStr = (String) serviceData.data.get("v4-serving-site"); + String v6ServingSiteStr = (String) serviceData.data.get("v6-serving-site"); + boolean v4ServingSite = v4ServingSiteStr != null && + (v4ServingSiteStr.equalsIgnoreCase("Y") || v4ServingSiteStr.equalsIgnoreCase("true")); + boolean v6ServingSite = v6ServingSiteStr != null && + (v6ServingSiteStr.equalsIgnoreCase("Y") || v6ServingSiteStr.equalsIgnoreCase("true")); + if (!v4ServingSite && !v6ServingSite) + return null; + + VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName); + + LimitAllocationRequest ar = new LimitAllocationRequest(); + ar.resourceSetId = resourceSetId; + ar.resourceUnionId = resourceUnionId; + ar.resourceName = "ServingSite"; + ar.assetId = equipmentData.equipmentId + "-" + vpnp.vpnId; + ar.missingResourceAction = AllocationAction.Succeed_Allocate; + ar.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar.replace = true; + ar.strict = false; + ar.checkLimit = 1; + ar.checkCount = 1; + ar.allocateCount = 1; + + return ar; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java new file mode 100644 index 00000000..f23f1e98 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.alloc; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +import org.openecomp.sdnc.ra.comp.AllocationRule; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.data.AllocationAction; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.LimitAllocationRequest; +import org.openecomp.sdnc.rm.data.MultiResourceAllocationRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VrfAllocationRule implements AllocationRule { + + private static final Logger log = LoggerFactory.getLogger(VrfAllocationRule.class); + + @Override + public AllocationRequest buildAllocationRequest( + String resourceUnionId, + String resourceSetId, + String endPointPosition, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + String vrfName = (String) serviceData.data.get("vrf-name"); + if (vrfName == null) + return null; + + log.info("vrfName: " + vrfName); + + Set resourceShareGroupList = new HashSet<>(); + resourceShareGroupList.add(vrfName); + + LimitAllocationRequest ar = new LimitAllocationRequest(); + ar.resourceSetId = resourceSetId; + ar.resourceUnionId = resourceUnionId; + ar.resourceShareGroupList = resourceShareGroupList; + ar.resourceName = "VRF"; + ar.assetId = equipmentData.equipmentId; + ar.missingResourceAction = AllocationAction.Succeed_Allocate; + ar.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar.replace = true; + ar.strict = false; + ar.checkLimit = 999999999; + ar.checkCount = 1; + ar.allocateCount = 1; + + String v4MulticastStr = (String) serviceData.data.get("v4-multicast"); + String v6MulticastStr = (String) serviceData.data.get("v6-multicast"); + boolean v4Multicast = v4MulticastStr != null && + (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true")); + boolean v6Multicast = v6MulticastStr != null && + (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true")); + if (v4Multicast || v6Multicast) { + LimitAllocationRequest ar2 = new LimitAllocationRequest(); + ar2.resourceSetId = resourceSetId; + ar2.resourceUnionId = resourceUnionId; + ar2.resourceShareGroupList = resourceShareGroupList; + ar2.resourceName = "MVRF"; + ar2.assetId = equipmentData.equipmentId; + ar2.missingResourceAction = AllocationAction.Succeed_Allocate; + ar2.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar2.replace = true; + ar2.strict = false; + ar2.checkLimit = 999999999; + ar2.checkCount = 1; + ar2.allocateCount = 1; + + MultiResourceAllocationRequest mar = new MultiResourceAllocationRequest(); + mar.resourceSetId = resourceSetId; + mar.resourceUnionId = resourceUnionId; + mar.resourceShareGroupList = resourceShareGroupList; + mar.assetId = equipmentData.equipmentId; + mar.missingResourceAction = AllocationAction.Succeed_Allocate; + mar.expiredResourceAction = AllocationAction.Succeed_Allocate; + mar.allocationRequestList = new ArrayList<>(); + mar.allocationRequestList.add(ar); + mar.allocationRequestList.add(ar2); + + return mar; + } + + return ar; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java new file mode 100644 index 00000000..aee761c7 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.check; + +import java.util.Map; + +import org.openecomp.sdnc.ra.comp.EquipmentCheck; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.AllocationItem; +import org.openecomp.sdnc.rm.data.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AnyVrfPresentCheck implements EquipmentCheck { + + private static final Logger log = LoggerFactory.getLogger(AnyVrfPresentCheck.class); + + private ResourceManager resourceManager; + + @Override + public boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints) { + String vrfNameListStr = (String) serviceData.data.get("vrf-name-list"); + if (vrfNameListStr == null) + vrfNameListStr = (String) serviceData.data.get("vrf-name"); + if (vrfNameListStr == null) + return true; + + String vrfRequiredStr = (String) equipmentConstraints.get("vrf-required"); + if (vrfRequiredStr == null || !vrfRequiredStr.equalsIgnoreCase("true")) + return true; + + String[] vrfNameList = vrfNameListStr.split(","); + + Resource r = resourceManager.getResource("VRF", equipData.equipmentId); + if (r != null && r.allocationItems != null) + for (AllocationItem ai : r.allocationItems) + for (String vrfName : vrfNameList) + if (ai.resourceShareGroupList.contains(vrfName)) + return true; + + log.info("Skipping VPE " + equipData.equipmentId + + ": Existing VRF is required, but there is no existing VRF on the VPE for any of the requested VPNs."); + return false; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java new file mode 100644 index 00000000..25571fb2 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.check; + +import java.util.Map; + +import org.openecomp.sdnc.ra.comp.EquipmentCheck; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ExcludeVpeCheck implements EquipmentCheck { + + private static final Logger log = LoggerFactory.getLogger(ExcludeVpeCheck.class); + + @Override + public boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints) { + String excludeVpeListStr = (String) equipmentConstraints.get("exclude-vpe-list"); + if (excludeVpeListStr == null) + return true; + + String vpeName = (String) equipData.data.get("vpe-id"); + + String[] excludeVpeList = excludeVpeListStr.split(","); + for (String excludeVpe : excludeVpeList) + if (excludeVpe.equals(vpeName)) { + log.info("Skipping VPE " + equipData.equipmentId + ": Present in the exclude VPE list."); + return false; + } + + return true; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java new file mode 100644 index 00000000..6c2b4c59 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.check; + +import java.util.Map; + +import org.openecomp.sdnc.ra.comp.EquipmentCheck; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.AllocationItem; +import org.openecomp.sdnc.rm.data.Resource; +import org.openecomp.sdnc.util.vrf.VpnParam; +import org.openecomp.sdnc.util.vrf.VrfUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HubWithRgCheck implements EquipmentCheck { + + private static final Logger log = LoggerFactory.getLogger(HubWithRgCheck.class); + + private ResourceManager resourceManager; + + @Override + public boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints) { + String vrfName = (String) serviceData.data.get("vrf-name"); + if (vrfName == null) + return true; + + // Check if this is HUB. If not, this check is not applicable + VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName); + if (vpnp.siteType == null || !vpnp.siteType.equals("HUB")) + return true; + + boolean rgPresent = vpnp.routeGroupName != null; + + // First check if a new VRF would be required. If not, we are good + Resource r = resourceManager.getResource("VRF", equipData.equipmentId); + if (r != null && r.allocationItems != null) { + for (AllocationItem ai : r.allocationItems) + if (ai.resourceShareGroupList.contains(vrfName)) + return true; + + String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition; + + // Check if there is already another HUB VRF with RG presence that does not match the requested + for (AllocationItem ai : r.allocationItems) { + + // Skip the allocation item for the current service instance, if there, in case it is a change order + if (ai.resourceUnionId.equals(resourceUnionId)) + continue; + + if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) { + String vrfName2 = ai.resourceShareGroupList.iterator().next(); + VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2); + + if (vpnp2.siteType == null || !vpnp2.siteType.equals("HUB")) + continue; + + boolean rgPresent2 = vpnp2.routeGroupName != null; + + if (rgPresent && !rgPresent2) { + log.info("Skipping VPE " + equipData.equipmentId + + ": This request requires new HUB with RG VRF, " + + "but there is already another HUB VRF with no RG: " + vrfName2 + "."); + return false; + } + if (!rgPresent && rgPresent2) { + log.info("Skipping VPE " + equipData.equipmentId + + ": This request requires new HUB VRF with no RG, " + + "but there is already another HUB with RG VRF: " + vrfName2 + "."); + return false; + } + } + } + } + + return true; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java new file mode 100644 index 00000000..56fd535e --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.check; + +import java.util.Map; + +import org.openecomp.sdnc.ra.comp.EquipmentCheck; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.AllocationItem; +import org.openecomp.sdnc.rm.data.Resource; +import org.openecomp.sdnc.util.vrf.VpnParam; +import org.openecomp.sdnc.util.vrf.VrfUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OneMVrfCheck implements EquipmentCheck { + + private static final Logger log = LoggerFactory.getLogger(OneMVrfCheck.class); + + private ResourceManager resourceManager; + + @Override + public boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints) { + String vrfName = (String) serviceData.data.get("vrf-name"); + if (vrfName == null) + return true; + + String v4MulticastStr = (String) serviceData.data.get("v4-multicast"); + String v6MulticastStr = (String) serviceData.data.get("v6-multicast"); + boolean v4Multicast = v4MulticastStr != null && + (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true")); + boolean v6Multicast = v6MulticastStr != null && + (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true")); + if (!v4Multicast && !v6Multicast) + return true; + + // First check if a new VRF would be required. If not, we are good + Resource r = resourceManager.getResource("VRF", equipData.equipmentId); + if (r != null && r.allocationItems != null) + for (AllocationItem ai : r.allocationItems) + if (ai.resourceShareGroupList.contains(vrfName)) + return true; + + String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition; + + // Check if there is already another multicast VRF for the same VPN + VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName); + r = resourceManager.getResource("MVRF", equipData.equipmentId); + if (r != null && r.allocationItems != null) { + for (AllocationItem ai : r.allocationItems) { + + // Skip the allocation item for the current service instance, if there, in case it is a change order + if (ai.resourceUnionId.equals(resourceUnionId)) + continue; + + if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) { + String vrfName2 = ai.resourceShareGroupList.iterator().next(); + VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2); + if (vpnp.vpnId.equals(vpnp2.vpnId)) { + log.info("Skipping VPE " + equipData.equipmentId + + ": This request requires new multicast VRF, " + + "but there is already another multicast VRF for the same VPN: " + vrfName2 + "."); + return false; + } + } + } + } + + return true; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java new file mode 100644 index 00000000..baed60eb --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.check; + +import java.util.Map; + +import org.openecomp.sdnc.ra.comp.EquipmentCheck; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ProvStatusCheck implements EquipmentCheck { + + private static final Logger log = LoggerFactory.getLogger(ProvStatusCheck.class); + + @Override + public boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints) { + String provStatus = (String) equipData.data.get("provisioning-status"); + if (provStatus == null || !provStatus.equals("PROV")) { + log.info("Skipping VPE " + equipData.equipmentId + ": Not in PROV status."); + return false; + } + return true; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java new file mode 100644 index 00000000..4644a14a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.check; + +import java.util.Map; + +import org.openecomp.sdnc.ra.comp.EquipmentCheck; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VlanSpeedCheck implements EquipmentCheck { + + private static final Logger log = LoggerFactory.getLogger(VlanSpeedCheck.class); + + @Override + public boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints) { + String vpeName = (String) equipData.data.get("vpe-id"); + Long serviceSpeed = (Long) serviceData.data.get("service-speed-kbps"); + if (serviceSpeed != null && serviceSpeed > 0 && serviceSpeed < 1000) { + log.info("Skipping VPE " + vpeName + ": Service speed < 1Mbps is not supported."); + return false; + } + return true; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java new file mode 100644 index 00000000..3b350b41 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.check; + +import java.util.Map; + +import org.openecomp.sdnc.ra.comp.EquipmentCheck; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.rule.dao.VpeLockDao; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.AllocationItem; +import org.openecomp.sdnc.rm.data.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VpeLockCheck implements EquipmentCheck { + + private static final Logger log = LoggerFactory.getLogger(VpeLockCheck.class); + + private VpeLockDao vpeLockDao; + private ResourceManager resourceManager; + + @Override + public boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints) { + String vrfName = (String) serviceData.data.get("vrf-name"); + if (vrfName == null) + return true; + + String vpeName = (String) equipData.data.get("vpe-id"); + String vpeLock = vpeLockDao.getVpeLock(vpeName); + if (vpeLock == null) + return true; + + if (vpeLock.equals("vpe-total-lock")) { + log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock + " on it."); + return false; + } + + if (vpeLock.equals("vpe-vrf-lock") && requiresNewVrf(equipData.equipmentId, vrfName)) { + log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock + + " on it and it requires a new VRF for VPN: " + vrfName + "."); + return false; + } + + if (vpeLock.equals("vpe-mvrf-lock") && requiresNewMVrf(equipData.equipmentId, vrfName)) { + log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock + + " on it and it requires a new multicast VRF for VPN: " + vrfName + "."); + return false; + } + + return true; + } + + boolean requiresNewVrf(String equipmentId, String vrfName) { + Resource r = resourceManager.getResource("VRF", equipmentId); + if (r == null || r.allocationItems == null) + return true; + + for (AllocationItem ai : r.allocationItems) { + if (ai.resourceShareGroupList.contains(vrfName)) + return false; + } + + return true; + } + + boolean requiresNewMVrf(String equipmentId, String vrfName) { + Resource r = resourceManager.getResource("MVRF", equipmentId); + if (r == null || r.allocationItems == null) + return true; + + for (AllocationItem ai : r.allocationItems) { + if (ai.resourceShareGroupList.contains(vrfName)) + return false; + } + + return true; + } + + public void setVpeLockDao(VpeLockDao vpeLockDao) { + this.vpeLockDao = vpeLockDao; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java new file mode 100644 index 00000000..0877933b --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.data.AllocationRequest; + +public interface AllocationRule { + + AllocationRequest buildAllocationRequest( + String resourceUnionId, + String resourceSetId, + String endPointPosition, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java new file mode 100644 index 00000000..21e49c3a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import java.util.List; + +import org.openecomp.sdnc.ra.equip.comp.EquipmentReader; + +public class EndPointAllocationDefinition { + + public String serviceModel; + public String endPointPosition; + public EquipmentReader equipmentReader; + public List equipmentCheckList; + public List preferenceRuleList; + public List allocationRuleList; + + public void setServiceModel(String serviceModel) { + this.serviceModel = serviceModel; + } + + public void setEndPointPosition(String endPointPosition) { + this.endPointPosition = endPointPosition; + } + + public void setEquipmentReader(EquipmentReader equipmentReader) { + this.equipmentReader = equipmentReader; + } + + public void setEquipmentCheckList(List equipmentCheckList) { + this.equipmentCheckList = equipmentCheckList; + } + + public void setPreferenceRuleList(List preferenceRuleList) { + this.preferenceRuleList = preferenceRuleList; + } + + public void setAllocationRuleList(List allocationRuleList) { + this.allocationRuleList = allocationRuleList; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java new file mode 100644 index 00000000..645c953c --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import java.util.List; +import java.util.Map; + +public interface EndPointAllocator { + + List allocateEndPoints( + ServiceData serviceData, + Map equipmentConstraints, + boolean checkOnly, + boolean change, + int changeNumber); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java new file mode 100644 index 00000000..1af81434 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java @@ -0,0 +1,214 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang.NotImplementedException; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.AllocationItem; +import org.openecomp.sdnc.rm.data.AllocationOutcome; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.AllocationStatus; +import org.openecomp.sdnc.rm.data.LimitAllocationItem; +import org.openecomp.sdnc.rm.data.LimitResource; +import org.openecomp.sdnc.rm.data.RangeAllocationItem; +import org.openecomp.sdnc.rm.data.RangeResource; +import org.openecomp.sdnc.rm.data.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class EndPointAllocatorImpl implements EndPointAllocator { + + private static final Logger log = LoggerFactory.getLogger(EndPointAllocatorImpl.class); + + private Map> endPointAllocationDefinitionMap; + + private ResourceManager resourceManager; + + @Override + public List allocateEndPoints( + ServiceData serviceData, + Map equipmentConstraints, + boolean checkOnly, + boolean change, + int changeNumber) { + List defList = endPointAllocationDefinitionMap.get(serviceData.serviceModel); + if (defList == null) + throw new NotImplementedException("Service model: " + serviceData.serviceModel + " not supported"); + + List epList = new ArrayList<>(); + for (EndPointAllocationDefinition def : defList) { + if (serviceData.endPointPosition != null && !serviceData.endPointPosition.equals(def.endPointPosition)) + continue; + + log.info( + "Starting allocation of end point: " + def.endPointPosition + ": " + serviceData.serviceInstanceId); + + String resourceUnionId = serviceData.serviceInstanceId + '/' + def.endPointPosition; + String resourceSetId = resourceUnionId + '/' + changeNumber; + + String equipmentId = (String) equipmentConstraints.get("equipment-id"); + if (equipmentId == null) { + EndPointData epExisting = readEndPoint(resourceUnionId, resourceSetId); + if (epExisting != null && epExisting.equipmentId != null) { + equipmentConstraints.put("equipment-id", epExisting.equipmentId); + + log.info("Trying assignment on the current equipment: " + epExisting.equipmentId); + } + } + + List equipList = def.equipmentReader.readEquipment(equipmentConstraints); + if (equipList == null || equipList.isEmpty()) { + log.info("Equipment not found for " + def.endPointPosition); + break; + } + + if (def.equipmentCheckList != null) { + for (EquipmentCheck filter : def.equipmentCheckList) { + List newEquipList = new ArrayList<>(); + for (EquipmentData equipData : equipList) + if (filter.checkEquipment(def.endPointPosition, serviceData, equipData, equipmentConstraints)) + newEquipList.add(equipData); + equipList = newEquipList; + } + if (equipList.isEmpty()) { + log.info("No equipment meets the requiremets for the service for: " + def.endPointPosition); + break; + } + } + + if (equipList.size() > 1 && def.preferenceRuleList != null && !def.preferenceRuleList.isEmpty()) { + + List prefEquipList = new ArrayList<>(); + for (EquipmentData equipData : equipList) { + PrefEquipment prefEquip = new PrefEquipment(); + prefEquip.equipData = equipData; + prefEquip.prefNumbers = new long[def.preferenceRuleList.size()]; + prefEquipList.add(prefEquip); + + int i = 0; + for (PreferenceRule prefRule : def.preferenceRuleList) + prefEquip.prefNumbers[i++] = + prefRule.assignOrderNumber(def.endPointPosition, serviceData, equipData); + } + + Collections.sort(prefEquipList); + + equipList = new ArrayList<>(); + for (PrefEquipment prefEquip : prefEquipList) + equipList.add(prefEquip.equipData); + } + + for (EquipmentData equipData : equipList) { + boolean allgood = true; + if (def.allocationRuleList != null) + for (AllocationRule allocationRule : def.allocationRuleList) { + AllocationRequest ar = allocationRule.buildAllocationRequest(resourceUnionId, resourceSetId, + def.endPointPosition, serviceData, equipData, checkOnly, change); + if (ar != null) { + AllocationOutcome ao = resourceManager.allocateResources(ar); + if (ao.status != AllocationStatus.Success) { + allgood = false; + break; + } + } + } + if (allgood) { + EndPointData ep = readEndPoint(resourceUnionId, resourceSetId); + epList.add(ep); + break; + } + } + } + + return epList; + } + + private EndPointData readEndPoint(String resourceUnionId, String resourceSetId) { + EndPointData ep = new EndPointData(); + ep.resourceUnionId = resourceUnionId; + ep.resourceSetId = resourceSetId; + + int i1 = resourceUnionId.indexOf('/'); + if (i1 > 0) + ep.endPointPosition = resourceUnionId.substring(i1 + 1); + + ep.data = new HashMap<>(); + + List rlist = resourceManager.getResourceUnion(resourceUnionId); + for (Resource r : rlist) { + if (r instanceof RangeResource) { + RangeResource rr = (RangeResource) r; + for (AllocationItem ai : r.allocationItems) + if (ai.resourceUnionId.equals(resourceUnionId)) { + RangeAllocationItem rai = (RangeAllocationItem) ai; + ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName, rai.used.first()); + } + } + if (r instanceof LimitResource) { + LimitResource rr = (LimitResource) r; + for (AllocationItem ai : r.allocationItems) + if (ai.resourceUnionId.equals(resourceUnionId)) { + LimitAllocationItem rai = (LimitAllocationItem) ai; + ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".allocated", rai.used); + ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".used", rr.used); + ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".assetId", + r.resourceKey.assetId); + } + } + } + + return ep; + } + + private static class PrefEquipment implements Comparable { + + public long[] prefNumbers; + public EquipmentData equipData; + + @Override + public int compareTo(PrefEquipment o) { + for (int i = 0; i < prefNumbers.length; i++) { + if (prefNumbers[i] < o.prefNumbers[i]) + return -1; + if (prefNumbers[i] > o.prefNumbers[i]) + return 1; + } + return 0; + } + } + + public void setEndPointAllocationDefinitionMap( + Map> endPointAllocationDefinitionMap) { + this.endPointAllocationDefinitionMap = endPointAllocationDefinitionMap; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java new file mode 100644 index 00000000..e425e373 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import java.util.Map; + +public class EndPointData { + + public String resourceSetId; + public String resourceUnionId; + public String endPointPosition; + public String equipmentId; + public Map data; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java new file mode 100644 index 00000000..fcca4f7c --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import java.util.Map; + +import org.openecomp.sdnc.ra.equip.data.EquipmentData; + +public interface EquipmentCheck { + + boolean checkEquipment( + String endPointPosition, + ServiceData serviceData, + EquipmentData equipData, + Map equipmentConstraints); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java new file mode 100644 index 00000000..acaf10d9 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import org.openecomp.sdnc.ra.equip.data.EquipmentData; + +public interface PreferenceRule { + + // Smaller order number is preferred + int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java new file mode 100644 index 00000000..0d29e54f --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.comp; + +import java.util.Map; + +public class ServiceData { + + public String serviceModel; + public String serviceInstanceId; + public String resourceSetId; + public String resourceUnionId; + public String resourceShareGroup; + public String endPointPosition; + public String resourceName; + public Map data; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java new file mode 100644 index 00000000..a380594b --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.comp; + +import java.util.List; +import java.util.Map; + +import org.openecomp.sdnc.ra.equip.data.EquipmentData; + +public interface EquipmentReader { + + List readEquipment(Map equipmentConstraints); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java new file mode 100644 index 00000000..44873873 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.dao; + +import java.util.List; +import java.util.Map; + +public interface ServerDao { + + List> getServerData(String aicSiteId); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java new file mode 100644 index 00000000..e1bc2a5a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.dao; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; + +public class ServerDaoImpl implements ServerDao { + + private static final Logger log = LoggerFactory.getLogger(ServerDaoImpl.class); + + private static final String GET_SERVER_COUNT_SQL = "SELECT count(*) FROM PSERVER WHERE aic_site_id = ?"; + + private JdbcTemplate jdbcTemplate; + + @Override + public List> getServerData(String aicSiteId) { + List> ll = new ArrayList>(); + Map sd = new HashMap(); + sd.put("aic-site-id", aicSiteId); + sd.put("server-id", aicSiteId + "/Server1"); + sd.put("server-model", "Unknown"); + sd.put("server-count", getServerCount(aicSiteId)); + ll.add(sd); + return ll; + } + + private int getServerCount(String aicSiteId) { + int n = jdbcTemplate.queryForInt(GET_SERVER_COUNT_SQL, aicSiteId); + + log.info("Number of servers in " + aicSiteId + ": " + n); + + return n; + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java new file mode 100644 index 00000000..4a0f6b8c --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.dao; + +import java.util.List; +import java.util.Map; + +public interface VpePortDao { + + List> getVpePortData(String aicSiteId); + + List> getVpePortData(String aicSiteId, String vpeName); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java new file mode 100644 index 00000000..d25fe9c4 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +public class VpePortDaoImpl implements VpePortDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(VpePortDaoImpl.class); + + private static final String GET_SQL = "SELECT * FROM VPE_POOL WHERE aic_site_id = ?"; + private static final String GET2_SQL = "SELECT * FROM VPE_POOL WHERE vpe_name = ?"; + private static final String GET3_SQL = + "SELECT * FROM VPE_POOL WHERE substring(aic_site_id, 1, 8) = substring(?, 1, 8)"; + + private JdbcTemplate jdbcTemplate; + + @Override + public List> getVpePortData(String aicSiteId) { + return jdbcTemplate.query(GET_SQL, new Object[] { aicSiteId }, new VpePortRowMapper()); + } + + @Override + public List> getVpePortData(String aicSiteId, String vpeName) { + String sql = vpeName != null ? GET2_SQL : GET3_SQL; + Object[] param = new Object[] { vpeName != null ? vpeName : aicSiteId }; + + return jdbcTemplate.query(sql, param, new VpePortRowMapper()); + } + + private static class VpePortRowMapper implements RowMapper> { + + @Override + public Map mapRow(ResultSet rs, int rowNum) throws SQLException { + Map mm = new HashMap(); + mm.put("vpe-id", rs.getString("vpe_name")); + mm.put("aic-site-id", rs.getString("aic_site_id")); + mm.put("availability-zone", rs.getString("availability_zone")); + mm.put("image-file-name", rs.getString("image_filename")); + mm.put("vendor", rs.getString("vendor")); + mm.put("provisioning-status", rs.getString("provisioning_status")); + mm.put("physical-interface-name", rs.getString("physical_intf_name")); + mm.put("physical-interface-speed", rs.getLong("physical_intf_speed")); + mm.put("physical-interface-speed-unit", rs.getString("physical_intf_units")); + return mm; + } + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java new file mode 100644 index 00000000..879a233d --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.dao; + +import java.util.List; +import java.util.Map; + +public interface VplspePortDao { + + List> getVplspePortData(String aicSiteId); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java new file mode 100644 index 00000000..bad64641 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +public class VplspePortDaoImpl implements VplspePortDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(VplspePortDaoImpl.class); + + private static final String GET_SQL = "SELECT * FROM VPLSPE_POOL WHERE aic_site_id = ?"; + + private JdbcTemplate jdbcTemplate; + + @Override + public List> getVplspePortData(String aicSiteId) { + List> ll = + jdbcTemplate.query(GET_SQL, new Object[] { aicSiteId }, new RowMapper>() { + + @Override + public Map mapRow(ResultSet rs, int rowNum) throws SQLException { + Map mm = new HashMap(); + mm.put("vplspe-id", rs.getString("vplspe_name")); + mm.put("aic-site-id", rs.getString("aic_site_id")); + mm.put("availability-zone", rs.getString("availability_zone")); + mm.put("image-file-name", rs.getString("image_filename")); + mm.put("vendor", rs.getString("vendor")); + mm.put("provisioning-status", rs.getString("provisioning_status")); + mm.put("physical-interface-name", rs.getString("physical_intf_name")); + mm.put("physical-interface-speed", rs.getLong("physical_intf_speed")); + mm.put("physical-interface-speed-unit", rs.getString("physical_intf_units")); + return mm; + } + }); + return ll; + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java new file mode 100644 index 00000000..d485224b --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.data; + +import java.util.Map; + +public class EquipmentData { + + public String equipmentId; + public EquipmentLevel equipmentLevel; + public Map data; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java new file mode 100644 index 00000000..44ae593a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.equip.data; + +public enum EquipmentLevel { + Port, Device, Server, Site +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java new file mode 100644 index 00000000..09af2081 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.pref; + +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.sdnc.ra.comp.PreferenceRule; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.LimitResource; +import org.openecomp.sdnc.rm.data.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AffinityLinkPref implements PreferenceRule { + + private static final Logger log = LoggerFactory.getLogger(AffinityLinkPref.class); + + private ResourceManager resourceManager; + private List affinityLinkIdList; + + public AffinityLinkPref() { + // Set default values for affinity link ids (can be overridden by the spring config) + affinityLinkIdList = new ArrayList<>(); + affinityLinkIdList.add("1"); + affinityLinkIdList.add("2"); + } + + @Override + public int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData) { + + // This class does not really assign order number, but instead sets the affinity link with the lowest + // assigned bandwidth in the equipment data + + String preferedAffinityLinkId = "1"; + long lowestAssignedBw = Long.MAX_VALUE; + for (String affinityLinkId : affinityLinkIdList) { + String assetId = equipData.equipmentId + "-" + affinityLinkId; + Resource r = resourceManager.getResource("Bandwidth", assetId); + if (r != null) { + LimitResource ll = (LimitResource) r; + if (ll.used < lowestAssignedBw) { + lowestAssignedBw = ll.used; + preferedAffinityLinkId = affinityLinkId; + } + log.info("Assigned bandwidth on affinity link: " + assetId + ": " + ll.used); + } + } + + equipData.data.put("affinity-link", preferedAffinityLinkId); + + log.info("Prefered affinity link for " + equipData.equipmentId + ": " + preferedAffinityLinkId); + + return 0; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } + + public void setAffinityLinkIdList(List affinityLinkIdList) { + this.affinityLinkIdList = affinityLinkIdList; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java new file mode 100644 index 00000000..abef0a24 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.pref; + +import org.openecomp.sdnc.ra.comp.PreferenceRule; +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.rm.comp.ResourceManager; +import org.openecomp.sdnc.rm.data.AllocationItem; +import org.openecomp.sdnc.rm.data.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class EvcExistingVrfPref implements PreferenceRule { + + private static final Logger log = LoggerFactory.getLogger(EvcExistingVrfPref.class); + + private ResourceManager resourceManager; + + @Override + public int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData) { + String vrfName = (String) serviceData.data.get("vrf-name"); + if (vrfName == null) + return 0; + + Resource r = resourceManager.getResource("VRF", equipData.equipmentId); + if (r != null && r.allocationItems != null) + for (AllocationItem ai : r.allocationItems) + if (ai.resourceShareGroupList.contains(vrfName)) { + log.info("VRF for VPN: " + vrfName + " found on VPE: " + equipData.equipmentId); + return 1; + } + + log.info("VRF for VPN: " + vrfName + " NOT found on VPE: " + equipData.equipmentId); + return 2; + } + + public void setResourceManager(ResourceManager resourceManager) { + this.resourceManager = resourceManager; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java new file mode 100644 index 00000000..4040b0b4 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.reader; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdnc.ra.equip.comp.EquipmentReader; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; + +public class AicSiteReader implements EquipmentReader { + + @Override + public List readEquipment(Map equipmentConstraints) { + String aicSiteId = (String) equipmentConstraints.get("aic-site-id"); + + EquipmentData equipData = new EquipmentData(); + equipData.equipmentLevel = EquipmentLevel.Site; + equipData.equipmentId = aicSiteId; + equipData.data = new HashMap(); + + List equipList = new ArrayList<>(); + equipList.add(equipData); + + return equipList; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java new file mode 100644 index 00000000..0adf6d12 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.reader; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdnc.ra.equip.comp.EquipmentReader; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; + +public class UplinkCircuitReader implements EquipmentReader { + + @SuppressWarnings("unchecked") + @Override + public List readEquipment(Map equipmentConstraints) { + List equipList = new ArrayList<>(); + + List> uplinkCircuitList = + (List>) equipmentConstraints.get("uplink-circuit-list"); + if (uplinkCircuitList == null || uplinkCircuitList.isEmpty()) + return equipList; + + for (Map uplinkCircuit : uplinkCircuitList) { + EquipmentData equipData = new EquipmentData(); + equipData.equipmentLevel = EquipmentLevel.Device; + equipData.equipmentId = (String) uplinkCircuit.get("uplink-circuit-id"); + equipData.data = uplinkCircuit; + equipList.add(equipData); + } + + return equipList; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java new file mode 100644 index 00000000..7039370a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.reader; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdnc.ra.equip.comp.EquipmentReader; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; + +public class VnfReader implements EquipmentReader { + + @Override + public List readEquipment(Map equipmentConstraints) { + String vnfName = (String) equipmentConstraints.get("vnf-name"); + + EquipmentData equipData = new EquipmentData(); + equipData.equipmentLevel = EquipmentLevel.Device; + equipData.equipmentId = vnfName; + equipData.data = new HashMap(); + + List equipList = new ArrayList<>(); + equipList.add(equipData); + + return equipList; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java new file mode 100644 index 00000000..360f7806 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.reader; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdnc.ra.equip.comp.EquipmentReader; +import org.openecomp.sdnc.ra.equip.dao.VpePortDao; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; + +public class VpePortReader implements EquipmentReader { + + private VpePortDao vpePortDao; + + @Override + public List readEquipment(Map equipmentConstraints) { + String clli = (String) equipmentConstraints.get("clli"); + String vpeName = (String) equipmentConstraints.get("vpe-name"); + if (vpeName == null) { + String equipmentId = (String) equipmentConstraints.get("equipment-id"); + if (equipmentId != null) { + int i1 = equipmentId.indexOf('/'); + if (i1 > 0) + equipmentId = equipmentId.substring(0, i1); + vpeName = equipmentId; + } + } + + List> vpeDataList = vpePortDao.getVpePortData(clli, vpeName); + + List equipList = new ArrayList<>(); + for (Map vpeData : vpeDataList) { + EquipmentData equipData = new EquipmentData(); + equipData.equipmentLevel = EquipmentLevel.Port; + equipData.equipmentId = + (String) vpeData.get("vpe-id") + '/' + (String) vpeData.get("physical-interface-name"); + equipData.data = vpeData; + + equipList.add(equipData); + } + + return equipList; + } + + public void setVpePortDao(VpePortDao vpePortDao) { + this.vpePortDao = vpePortDao; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java new file mode 100644 index 00000000..44e4c53a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.comp; + +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.rule.data.ThresholdStatus; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.LimitAllocationOutcome; + +public interface AllocationRequestBuilder { + + AllocationRequest buildAllocationRequest( + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change); + + ThresholdStatus getThresholdStatus( + ServiceData serviceData, + EquipmentData equipmentData, + LimitAllocationOutcome limitAllocationOutcome); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java new file mode 100644 index 00000000..dbc0d8be --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.comp; + +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.sdnc.ra.comp.ServiceData; +import org.openecomp.sdnc.ra.equip.data.EquipmentData; +import org.openecomp.sdnc.ra.rule.dao.RangeRuleDao; +import org.openecomp.sdnc.ra.rule.dao.ResourceRuleDao; +import org.openecomp.sdnc.ra.rule.data.RangeRule; +import org.openecomp.sdnc.ra.rule.data.ResourceRule; +import org.openecomp.sdnc.ra.rule.data.ResourceThreshold; +import org.openecomp.sdnc.ra.rule.data.ThresholdStatus; +import org.openecomp.sdnc.rm.data.AllocationAction; +import org.openecomp.sdnc.rm.data.AllocationRequest; +import org.openecomp.sdnc.rm.data.LimitAllocationOutcome; +import org.openecomp.sdnc.rm.data.LimitAllocationRequest; +import org.openecomp.sdnc.rm.data.MultiResourceAllocationRequest; +import org.openecomp.sdnc.rm.data.RangeAllocationRequest; +import org.openecomp.sdnc.util.expr.ExpressionEvaluator; +import org.openecomp.sdnc.util.str.StrUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AllocationRequestBuilderImpl implements AllocationRequestBuilder { + + private static final Logger log = LoggerFactory.getLogger(AllocationRequestBuilderImpl.class); + + private ResourceRuleDao resourceRuleDao; + private RangeRuleDao rangeRuleDao; + + @Override + public AllocationRequest buildAllocationRequest( + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + List resourceRuleList = resourceRuleDao.getResourceRules(serviceData.serviceModel, + serviceData.endPointPosition, equipmentData.equipmentLevel); + List rangeRuleList = rangeRuleDao.getRangeRules(serviceData.serviceModel, + serviceData.endPointPosition, equipmentData.equipmentLevel); + if (resourceRuleList.isEmpty() && rangeRuleList.isEmpty()) + return null; + if (resourceRuleList.size() == 1 && rangeRuleList.isEmpty()) + return buildAllocationRequest(resourceRuleList.get(0), serviceData, equipmentData, checkOnly, change); + + if (resourceRuleList.isEmpty() && rangeRuleList.size() == 1) + return buildAllocationRequest(rangeRuleList.get(0), serviceData, equipmentData, checkOnly, change); + + MultiResourceAllocationRequest ar = new MultiResourceAllocationRequest(); + ar.stopOnFirstFailure = false; + ar.allocationRequestList = new ArrayList(); + for (ResourceRule rr : resourceRuleList) { + AllocationRequest ar1 = buildAllocationRequest(rr, serviceData, equipmentData, checkOnly, change); + ar.allocationRequestList.add(ar1); + } + for (RangeRule rr : rangeRuleList) { + AllocationRequest ar1 = buildAllocationRequest(rr, serviceData, equipmentData, checkOnly, change); + ar.allocationRequestList.add(ar1); + } + return ar; + } + + private AllocationRequest buildAllocationRequest( + ResourceRule resourceRule, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + StrUtil.info(log, resourceRule); + + LimitAllocationRequest ar = new LimitAllocationRequest(); + ar.resourceSetId = serviceData.resourceSetId; + ar.resourceUnionId = serviceData.resourceUnionId; + ar.resourceName = resourceRule.resourceName; + ar.assetId = equipmentData.equipmentId; + ar.missingResourceAction = AllocationAction.Succeed_Allocate; + ar.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar.replace = true; + ar.strict = false; + ar.checkLimit = ExpressionEvaluator.evalLong( + change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, equipmentData.data); + ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, serviceData.data); + ar.allocateCount = checkOnly ? 0 : ar.checkCount; + return ar; + } + + private AllocationRequest buildAllocationRequest( + RangeRule rangeRule, + ServiceData serviceData, + EquipmentData equipmentData, + boolean checkOnly, + boolean change) { + StrUtil.info(log, rangeRule); + + RangeAllocationRequest ar = new RangeAllocationRequest(); + ar.resourceSetId = serviceData.resourceSetId; + ar.resourceUnionId = serviceData.resourceUnionId; + ar.resourceName = rangeRule.rangeName; + ar.assetId = equipmentData.equipmentId; + ar.missingResourceAction = AllocationAction.Succeed_Allocate; + ar.expiredResourceAction = AllocationAction.Succeed_Allocate; + ar.replace = true; + ar.check = true; + ar.allocate = !checkOnly; + ar.checkMin = rangeRule.minValue; + ar.checkMax = rangeRule.maxValue; + return ar; + } + + @Override + public ThresholdStatus getThresholdStatus( + ServiceData serviceData, + EquipmentData equipmentData, + LimitAllocationOutcome limitAllocationOutcome) { + ResourceRule rr = resourceRuleDao.getResourceRule(serviceData.serviceModel, serviceData.endPointPosition, + equipmentData.equipmentLevel, limitAllocationOutcome.request.resourceName); + if (rr == null || rr.thresholdList == null || rr.thresholdList.isEmpty()) + return null; + + ThresholdStatus thresholdStatus = null; + long maxThresholdValue = 0; + for (ResourceThreshold th : rr.thresholdList) { + long thresholdValue = ExpressionEvaluator.evalLong(th.expression, equipmentData.data); + + if (thresholdValue > maxThresholdValue) { + maxThresholdValue = thresholdValue; + + if (limitAllocationOutcome.used >= thresholdValue) { + thresholdStatus = new ThresholdStatus(); + thresholdStatus.resourceRule = rr; + thresholdStatus.resourceThreshold = th; + thresholdStatus.limitValue = limitAllocationOutcome.limit; + thresholdStatus.thresholdValue = thresholdValue; + thresholdStatus.used = limitAllocationOutcome.used; + thresholdStatus.lastAdded = limitAllocationOutcome.allocatedCount; + } + } + } + + return thresholdStatus; + } + + public void setResourceRuleDao(ResourceRuleDao resourceRuleDao) { + this.resourceRuleDao = resourceRuleDao; + } + + public void setRangeRuleDao(RangeRuleDao rangeRuleDao) { + this.rangeRuleDao = rangeRuleDao; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java new file mode 100644 index 00000000..a56b7880 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +public interface MaxPortSpeedDao { + + // Returns max speed in kbps + long getMaxPortSpeed(String imageFile, String endPointPosition, String interfaceName); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java new file mode 100644 index 00000000..ea0bd771 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.openecomp.sdnc.util.speed.SpeedUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +public class MaxPortSpeedDaoImpl implements MaxPortSpeedDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(MaxPortSpeedDaoImpl.class); + + private final static String GET_SQL = + "SELECT * FROM MAX_PORT_SPEED WHERE image_file_name = ? AND end_point_position = ? AND interface_name = ?"; + + private JdbcTemplate jdbcTemplate; + private long defaultMaxPortSpeed = 5000000; + private SpeedUtil speedUtil; + + @Override + public long getMaxPortSpeed(String imageFile, String endPointPosition, String interfaceName) { + List maxPortSpeedList = + jdbcTemplate.query(GET_SQL, new Object[] { imageFile, endPointPosition, interfaceName }, + new RowMapper() { + + @Override + public MaxPortSpeed mapRow(ResultSet rs, int rowNum) throws SQLException { + MaxPortSpeed mps = new MaxPortSpeed(); + mps.maxSpeed = rs.getLong("max_speed"); + mps.unit = rs.getString("unit"); + return mps; + } + }); + + if (maxPortSpeedList.isEmpty()) + return defaultMaxPortSpeed; + + MaxPortSpeed mps = maxPortSpeedList.get(0); + return speedUtil.convertToKbps(mps.maxSpeed, mps.unit); + } + + private static class MaxPortSpeed { + + public long maxSpeed; + public String unit; + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + public void setDefaultMaxPortSpeed(long defaultMaxPortSpeed) { + this.defaultMaxPortSpeed = defaultMaxPortSpeed; + } + + public void setSpeedUtil(SpeedUtil speedUtil) { + this.speedUtil = speedUtil; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java new file mode 100644 index 00000000..4bd17f1d --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +public interface MaxServerSpeedDao { + + // Returns max speed in kbps + long getMaxServerSpeed(String serverModel, int evcCount); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java new file mode 100644 index 00000000..c3428179 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.openecomp.sdnc.util.speed.SpeedUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +public class MaxServerSpeedDaoImpl implements MaxServerSpeedDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(MaxServerSpeedDaoImpl.class); + + private final static String GET_SQL = + "SELECT * FROM MAX_SERVER_SPEED\n" + + "WHERE (server_model = ? OR server_model = 'ALL') AND evc_count >= ?\n" + + "ORDER BY evc_count"; + + private JdbcTemplate jdbcTemplate; + private long defaultMaxServerSpeed = 1600000; + private SpeedUtil speedUtil; + + @Override + public long getMaxServerSpeed(String serverModel, int evcCount) { + List maxServerSpeedList = + jdbcTemplate.query(GET_SQL, new Object[] { serverModel, evcCount }, new RowMapper() { + + @Override + public MaxServerSpeed mapRow(ResultSet rs, int rowNum) throws SQLException { + MaxServerSpeed mps = new MaxServerSpeed(); + mps.maxSpeed = rs.getLong("max_speed"); + mps.unit = rs.getString("unit"); + return mps; + } + }); + + if (maxServerSpeedList.isEmpty()) + return defaultMaxServerSpeed; + + MaxServerSpeed mps = maxServerSpeedList.get(0); + return speedUtil.convertToKbps(mps.maxSpeed, mps.unit); + } + + private static class MaxServerSpeed { + + public long maxSpeed; + public String unit; + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + public void setDefaultMaxServerSpeed(long defaultMaxServerSpeed) { + this.defaultMaxServerSpeed = defaultMaxServerSpeed; + } + + public void setSpeedUtil(SpeedUtil speedUtil) { + this.speedUtil = speedUtil; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java new file mode 100644 index 00000000..509a034a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +public interface ParameterDao { + + String getParameter(String name); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java new file mode 100644 index 00000000..2cafb280 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; + +public class ParameterDaoImpl implements ParameterDao { + + private static final Logger log = LoggerFactory.getLogger(ParameterDaoImpl.class); + + private final static String GET_SQL = "SELECT * FROM PARAMETERS WHERE name = ?"; + + private JdbcTemplate jdbcTemplate; + + @Override + public String getParameter(String name) { + List> ll = jdbcTemplate.queryForList(GET_SQL, name); + + if (ll == null || ll.isEmpty()) { + log.info("Parameter: " + name + " not found in DB"); + return null; + } + + String v = (String) ll.get(0).get("value"); + log.info("Parameter from DB: " + name + "='" + v + "'"); + + return v; + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java new file mode 100644 index 00000000..798a2303 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.util.List; + +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; +import org.openecomp.sdnc.ra.rule.data.RangeRule; + +public interface RangeRuleDao { + + List getRangeRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java new file mode 100644 index 00000000..dec05ece --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; +import org.openecomp.sdnc.ra.rule.data.RangeRule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +public class RangeRuleDaoImpl implements RangeRuleDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(RangeRuleDaoImpl.class); + + private static final String GET_SQL = + "SELECT * FROM RANGE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ?"; + + private JdbcTemplate jdbcTemplate; + + @Override + public List getRangeRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel) { + List rangeRuleList = + jdbcTemplate.query(GET_SQL, new Object[] { serviceModel, endPointPosition, equipLevel.toString() }, + new RowMapper() { + + @Override + public RangeRule mapRow(ResultSet rs, int rowNum) throws SQLException { + RangeRule rl = new RangeRule(); + rl.id = rs.getLong("range_rule_id"); + rl.rangeName = rs.getString("range_name"); + rl.serviceModel = rs.getString("service_model"); + rl.endPointPosition = rs.getString("end_point_position"); + rl.equipmentLevel = rs.getString("equipment_level"); + rl.minValue = rs.getInt("min_value"); + rl.maxValue = rs.getInt("max_value"); + return rl; + } + }); + return rangeRuleList; + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java new file mode 100644 index 00000000..31ce9e6a --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.util.List; + +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; +import org.openecomp.sdnc.ra.rule.data.ResourceRule; + +public interface ResourceRuleDao { + + List getResourceRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel); + + ResourceRule getResourceRule( + String serviceModel, + String endPointPosition, + EquipmentLevel equipLevel, + String resourceName); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java new file mode 100644 index 00000000..819a01cd --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.openecomp.sdnc.ra.equip.data.EquipmentLevel; +import org.openecomp.sdnc.ra.rule.data.ResourceRule; +import org.openecomp.sdnc.ra.rule.data.ResourceThreshold; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +public class ResourceRuleDaoImpl implements ResourceRuleDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(ResourceRuleDaoImpl.class); + + private static final String GET1_SQL = + "SELECT * FROM RESOURCE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ?"; + private static final String GET2_SQL = + "SELECT * FROM RESOURCE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ? AND resource_name = ?"; + private static final String THRESHOLD_SQL = "SELECT * FROM RESOURCE_THRESHOLD WHERE resource_rule_id = ?"; + + private JdbcTemplate jdbcTemplate; + ResourceRuleRowMapper resourceRuleRowMapper = new ResourceRuleRowMapper(); + ResourceThresholdRowMapper resourceThresholdRowMapper = new ResourceThresholdRowMapper(); + + @Override + public List getResourceRules( + String serviceModel, + String endPointPosition, + EquipmentLevel equipLevel) { + List resourceRuleList = jdbcTemplate.query(GET1_SQL, + new Object[] { serviceModel, endPointPosition, equipLevel.toString() }, resourceRuleRowMapper); + + for (ResourceRule rr : resourceRuleList) + rr.thresholdList = jdbcTemplate.query(THRESHOLD_SQL, new Object[] { rr.id }, resourceThresholdRowMapper); + + return resourceRuleList; + } + + @Override + public ResourceRule getResourceRule( + String serviceModel, + String endPointPosition, + EquipmentLevel equipLevel, + String resourceName) { + List resourceRuleList = jdbcTemplate.query(GET2_SQL, + new Object[] { serviceModel, endPointPosition, equipLevel.toString(), resourceName }, + resourceRuleRowMapper); + + if (resourceRuleList == null || resourceRuleList.isEmpty()) + return null; + + ResourceRule rr = resourceRuleList.get(0); + rr.thresholdList = jdbcTemplate.query(THRESHOLD_SQL, new Object[] { rr.id }, resourceThresholdRowMapper); + + return rr; + } + + private static class ResourceRuleRowMapper implements RowMapper { + + @Override + public ResourceRule mapRow(ResultSet rs, int rowNum) throws SQLException { + ResourceRule rl = new ResourceRule(); + rl.id = rs.getLong("resource_rule_id"); + rl.resourceName = rs.getString("resource_name"); + rl.serviceModel = rs.getString("service_model"); + rl.endPointPosition = rs.getString("end_point_position"); + rl.serviceExpression = rs.getString("service_expression"); + rl.equipmentLevel = rs.getString("equipment_level"); + rl.equipmentExpression = rs.getString("equipment_expression"); + rl.allocationExpression = rs.getString("allocation_expression"); + rl.softLimitExpression = rs.getString("soft_limit_expression"); + rl.hardLimitExpression = rs.getString("hard_limit_expression"); + return rl; + } + } + + private static class ResourceThresholdRowMapper implements RowMapper { + + @Override + public ResourceThreshold mapRow(ResultSet rs, int rowNum) throws SQLException { + ResourceThreshold th = new ResourceThreshold(); + th.expression = rs.getString("threshold_expression"); + th.message = rs.getString("threshold_message"); + return th; + } + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java new file mode 100644 index 00000000..eb41792d --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +public interface VpeLockDao { + + String getVpeLock(String vpeName); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java new file mode 100644 index 00000000..eb6cef3b --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.dao; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; + +public class VpeLockDaoImpl implements VpeLockDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(VpeLockDaoImpl.class); + + private final static String GET_SQL = "SELECT vpn_lock FROM VPE_LOCK WHERE vpe_name = ?"; + + private JdbcTemplate jdbcTemplate; + + @Override + public String getVpeLock(String vpeName) { + List ll = jdbcTemplate.queryForList(GET_SQL, String.class, vpeName); + return ll != null && !ll.isEmpty() ? ll.get(0) : null; + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java new file mode 100644 index 00000000..ed76f6b1 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.data; + +public class RangeRule { + + public long id; + public String rangeName; + public String serviceModel; + public String endPointPosition; + public String equipmentLevel; + public int minValue; + public int maxValue; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java new file mode 100644 index 00000000..c4d55f92 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.data; + +import java.util.List; + +public class ResourceRule { + + public long id; + public String resourceName; + public String serviceModel; + public String endPointPosition; + public String serviceExpression; + public String equipmentLevel; + public String equipmentExpression; + public String allocationExpression; + public String softLimitExpression; + public String hardLimitExpression; + public List thresholdList; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java new file mode 100644 index 00000000..7be4067e --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.data; + +public class ResourceThreshold { + + public String expression; + public String message; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java new file mode 100644 index 00000000..5f772ef1 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.rule.data; + +public class ThresholdStatus { + + public ResourceRule resourceRule; + public ResourceThreshold resourceThreshold; + public long limitValue; + public long thresholdValue; + public long used; + public long lastAdded; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java new file mode 100644 index 00000000..811118cb --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.service.dao; + +import org.openecomp.sdnc.ra.service.data.ServiceResource; +import org.openecomp.sdnc.ra.service.data.ServiceStatus; + +public interface ServiceResourceDao { + + ServiceResource getServiceResource(String serviceInstanceId, ServiceStatus serviceStatus); + + void addServiceResource(ServiceResource serviceResource); + + void updateServiceResource(ServiceResource serviceResource); + + void deleteServiceResource(String serviceInstanceId, ServiceStatus serviceStatus); + + void updateServiceStatus(String serviceInstanceId, ServiceStatus serviceStatus, ServiceStatus newServiceStatus); +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java new file mode 100644 index 00000000..6432e80d --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.service.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.openecomp.sdnc.ra.service.data.ServiceResource; +import org.openecomp.sdnc.ra.service.data.ServiceStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +public class ServiceResourceDaoImpl implements ServiceResourceDao { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(ServiceResourceDaoImpl.class); + + private static final String GET_SQL = + "SELECT * FROM SERVICE_RESOURCE WHERE service_instance_id = ? AND service_status = ?"; + + private static final String ADD_SQL = "INSERT INTO SERVICE_RESOURCE (\n" + + " service_instance_id, service_status, service_change_number, resource_set_id, resource_union_id)\n" + + "VALUES (?, ?, ?, ?, ?)"; + + private static final String UPDATE_SQL = + "UPDATE SERVICE_RESOURCE SET service_change_number = ?, resource_set_id = ?\n" + + "WHERE service_instance_id = ? AND service_status = ?"; + + private static final String DELETE_SQL = + "DELETE FROM SERVICE_RESOURCE WHERE service_instance_id = ? AND service_status = ?"; + + private static final String UPDATE_STATUS_SQL = + "UPDATE SERVICE_RESOURCE SET service_status = ? WHERE service_instance_id = ? AND service_status = ?"; + + private JdbcTemplate jdbcTemplate; + + @Override + public ServiceResource getServiceResource(final String serviceInstanceId, final ServiceStatus serviceStatus) { + List serviceResourceList = + jdbcTemplate.query(GET_SQL, new Object[] { serviceInstanceId, serviceStatus.toString() }, + new RowMapper() { + + @Override + public ServiceResource mapRow(ResultSet rs, int rowNum) throws SQLException { + ServiceResource sr = new ServiceResource(); + sr.id = rs.getLong("service_resource_id"); + sr.serviceInstanceId = serviceInstanceId; + sr.serviceStatus = serviceStatus; + sr.serviceChangeNumber = rs.getInt("service_change_number"); + sr.resourceSetId = rs.getString("resource_set_id"); + sr.resourceUnionId = rs.getString("resource_union_id"); + return sr; + } + }); + if (serviceResourceList.isEmpty()) + return null; + return serviceResourceList.get(0); + } + + @Override + public void addServiceResource(ServiceResource serviceResource) { + jdbcTemplate.update(ADD_SQL, serviceResource.serviceInstanceId, serviceResource.serviceStatus.toString(), + serviceResource.serviceChangeNumber, serviceResource.resourceSetId, serviceResource.resourceUnionId); + } + + @Override + public void updateServiceResource(ServiceResource serviceResource) { + jdbcTemplate.update(UPDATE_SQL, serviceResource.serviceChangeNumber, serviceResource.resourceSetId, + serviceResource.serviceInstanceId, serviceResource.serviceStatus.toString()); + } + + @Override + public void deleteServiceResource(String serviceInstanceId, ServiceStatus serviceStatus) { + jdbcTemplate.update(DELETE_SQL, serviceInstanceId, serviceStatus.toString()); + } + + @Override + public void updateServiceStatus( + String serviceInstanceId, + ServiceStatus serviceStatus, + ServiceStatus newServiceStatus) { + jdbcTemplate.update(UPDATE_STATUS_SQL, newServiceStatus.toString(), serviceInstanceId, serviceStatus.toString()); + } + + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java new file mode 100644 index 00000000..65d4488e --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.service.data; + +public class ServiceResource { + + public long id; + public String serviceInstanceId; + public ServiceStatus serviceStatus; + public int serviceChangeNumber; + public String resourceSetId; + public String resourceUnionId; +} diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java new file mode 100644 index 00000000..32f473d3 --- /dev/null +++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.ra.service.data; + +public enum ServiceStatus { + + Active, Pending +} -- cgit 1.2.3-korg