2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.adaptors.rm.util;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import org.onap.ccsdk.sli.adaptors.rm.data.AllocationItem;
27 import org.onap.ccsdk.sli.adaptors.rm.data.LabelAllocationItem;
28 import org.onap.ccsdk.sli.adaptors.rm.data.LabelAllocationRequest;
29 import org.onap.ccsdk.sli.adaptors.rm.data.LabelResource;
30 import org.onap.ccsdk.sli.adaptors.rm.data.ResourceKey;
31 import org.onap.ccsdk.sli.adaptors.rm.data.ResourceType;
33 public class LabelUtil {
35 public static boolean checkLabel(LabelResource l, LabelAllocationRequest req) {
36 if (req.check && req.label != null && l.allocationItems != null && !l.allocationItems.isEmpty()) {
37 for (AllocationItem ai : l.allocationItems) {
38 LabelAllocationItem lai = (LabelAllocationItem) ai;
39 if (!eq(req.resourceUnionId, lai.resourceUnionId) && !eq(req.label, lai.label)) {
47 public static String allocateLabel(LabelResource l, LabelAllocationRequest req) {
52 LabelAllocationItem lai = (LabelAllocationItem) ResourceUtil.getAllocationItem(l, req.resourceSetId);
54 lai = new LabelAllocationItem();
55 lai.resourceType = ResourceType.Label;
56 lai.resourceKey = new ResourceKey();
57 lai.resourceKey.assetId = req.assetId;
58 lai.resourceKey.resourceName = req.resourceName;
59 lai.applicationId = req.applicationId;
60 lai.resourceSetId = req.resourceSetId;
61 lai.resourceUnionId = req.resourceUnionId;
62 lai.resourceShareGroupList = req.resourceShareGroupList;
64 if (l.allocationItems == null) {
65 l.allocationItems = new ArrayList<>();
67 l.allocationItems.add(lai);
70 lai.label = req.label;
71 lai.allocationTime = new Date();
78 public static void recalculate(LabelResource l) {
81 if (l.allocationItems != null) {
82 for (AllocationItem ai : l.allocationItems) {
83 LabelAllocationItem lai = (LabelAllocationItem) ai;
84 if (lai.label != null) {
86 if (l.label == null) {
88 } else if (!l.label.equals(lai.label)) {
89 l.label = "__BLOCKED__";
96 private static boolean eq(Object o1, Object o2) {
97 return o1 == null ? o2 == null : o1.equals(o2);