2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP 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.openecomp.sdnc.rm.comp;
24 import java.util.Collection;
25 import java.util.Iterator;
26 import java.util.List;
28 import org.openecomp.sdnc.lock.comp.LockHelper;
29 import org.openecomp.sdnc.lock.comp.ResourceLockedException;
30 import org.openecomp.sdnc.lock.comp.SynchronizedFunction;
31 import org.openecomp.sdnc.rm.dao.ResourceDao;
32 import org.openecomp.sdnc.rm.data.AllocationItem;
33 import org.openecomp.sdnc.rm.data.Resource;
34 import org.openecomp.sdnc.rm.util.ResourceUtil;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 class ReleaseFunction extends SynchronizedFunction {
40 @SuppressWarnings("unused")
41 private static final Logger log = LoggerFactory.getLogger(ReleaseFunction.class);
43 private ResourceDao resourceDao;
45 private String resourceSetId, resourceUnionId;
47 public ReleaseFunction(LockHelper lockHelper, ResourceDao resourceDao, String resourceSetId,
48 String resourceUnionId, Collection<String> lockNames, int lockTimeout) {
49 super(lockHelper, lockNames, lockTimeout);
50 this.resourceDao = resourceDao;
51 this.resourceSetId = resourceSetId;
52 this.resourceUnionId = resourceUnionId;
56 public void _exec() throws ResourceLockedException {
57 List<Resource> resourceList =
59 ? resourceDao.getResourceSet(resourceSetId) : resourceDao.getResourceUnion(resourceUnionId);
60 for (Resource r : resourceList) {
61 boolean updated = false;
62 if (r.allocationItems != null) {
63 Iterator<AllocationItem> i = r.allocationItems.iterator();
65 AllocationItem ai = i.next();
66 if (resourceSetId != null) {
67 if (resourceSetId.equals(ai.resourceSetId)) {
72 } else if (resourceUnionId != null) {
74 if (resourceUnionId.equals(ai.resourceUnionId)) {
83 ResourceUtil.recalculate(r);
84 resourceDao.saveResource(r);