aboutsummaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp
diff options
context:
space:
mode:
Diffstat (limited to 'resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp')
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java37
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java60
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java35
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java184
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java33
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java35
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java30
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java34
8 files changed, 448 insertions, 0 deletions
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 0000000..00d8af4
--- /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 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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 0000000..43eb79f
--- /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 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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<EquipmentCheck> equipmentCheckList;
+ public List<PreferenceRule> preferenceRuleList;
+ public List<AllocationRule> 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<EquipmentCheck> equipmentCheckList) {
+ this.equipmentCheckList = equipmentCheckList;
+ }
+
+ public void setPreferenceRuleList(List<PreferenceRule> preferenceRuleList) {
+ this.preferenceRuleList = preferenceRuleList;
+ }
+
+ public void setAllocationRuleList(List<AllocationRule> 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 0000000..1212612
--- /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 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.ra.comp;
+
+import java.util.List;
+import java.util.Map;
+
+public interface EndPointAllocator {
+
+ List<EndPointData> allocateEndPoints(
+ ServiceData serviceData,
+ Map<String, Object> 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 0000000..7b042ea
--- /dev/null
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java
@@ -0,0 +1,184 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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.AllocationOutcome;
+import org.openecomp.sdnc.rm.data.AllocationRequest;
+import org.openecomp.sdnc.rm.data.AllocationStatus;
+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<String, List<EndPointAllocationDefinition>> endPointAllocationDefinitionMap;
+
+ private ResourceManager resourceManager;
+
+ @Override
+ public List<EndPointData> allocateEndPoints(
+ ServiceData serviceData,
+ Map<String, Object> equipmentConstraints,
+ boolean checkOnly,
+ boolean change,
+ int changeNumber) {
+ List<EndPointAllocationDefinition> defList = endPointAllocationDefinitionMap.get(serviceData.serviceModel);
+ if (defList == null)
+ throw new NotImplementedException("Service model: " + serviceData.serviceModel + " not supported");
+
+ List<EndPointData> epList = new ArrayList<>();
+ for (EndPointAllocationDefinition def : defList) {
+ log.info(
+ "Starting allocation of end point: " + def.endPointPosition + ": " + serviceData.serviceInstanceId);
+
+ List<EquipmentData> 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<EquipmentData> 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<PrefEquipment> 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);
+ }
+
+ String resourceUnionId = serviceData.serviceInstanceId + '/' + def.endPointPosition;
+ String resourceSetId = resourceUnionId + '/' + changeNumber;
+
+ 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<Resource> rlist = resourceManager.getResourceUnion(resourceUnionId);
+ for (Resource r : rlist) {
+ if (r instanceof RangeResource) {
+ RangeResource rr = (RangeResource) r;
+ ep.data.put(rr.resourceKey.resourceName, rr.used.first());
+
+ ep.equipmentId = r.resourceKey.assetId;
+ }
+ }
+
+ return ep;
+ }
+
+ private static class PrefEquipment implements Comparable<PrefEquipment> {
+
+ 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<String, List<EndPointAllocationDefinition>> 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 0000000..900075b
--- /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 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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<String, Object> 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 0000000..5bc2018
--- /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 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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<String, Object> 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 0000000..490dbb1
--- /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 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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 0000000..46da423
--- /dev/null
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.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 endPointPosition;
+ public Map<String, Object> data;
+}