2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.impl.instance;
23 import org.openecomp.sdc.be.dao.api.ActionStatus;
24 import org.openecomp.sdc.be.model.Component;
25 import org.openecomp.sdc.be.model.ComponentInstance;
26 import org.openecomp.sdc.common.log.wrappers.Logger;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.function.Function;
32 @org.springframework.stereotype.Component
33 public class ComponentInstanceChangeOperationOrchestrator {
35 private static final Logger log = Logger.getLogger(ComponentInstanceChangeOperationOrchestrator.class);
36 private final List<OnComponentInstanceChangeOperation> onInstanceChangeOperations;
38 public ComponentInstanceChangeOperationOrchestrator(List<OnComponentInstanceChangeOperation> onInstanceChangeOperations) {
39 this.onInstanceChangeOperations = onInstanceChangeOperations;
42 public ActionStatus doPostChangeVersionOperations(Component container, ComponentInstance prevVersion, ComponentInstance newVersion) {
43 log.debug("#doPostChangeVersionOperations - starting post change version operations for component {}. from instance {} to instance {}", container.getUniqueId(), prevVersion.getUniqueId(), newVersion.getUniqueId());
44 Function<OnComponentInstanceChangeOperation, ActionStatus> instanceChangeTaskRunner = operation -> operation.onChangeVersion(container, prevVersion, newVersion);
45 return doOnChangeInstanceOperations(instanceChangeTaskRunner);
48 public ActionStatus doOnDeleteInstanceOperations(Component container, String deletedInstanceId) {
49 log.debug("#doPostChangeVersionOperations - starting on delete instance operations for component {} and instance {}.", container.getUniqueId(), deletedInstanceId);
50 Function<OnComponentInstanceChangeOperation, ActionStatus> instanceChangeTaskRunner = operation -> operation.onDelete(container, deletedInstanceId);
51 return doOnChangeInstanceOperations(instanceChangeTaskRunner);
54 private ActionStatus doOnChangeInstanceOperations(Function<OnComponentInstanceChangeOperation, ActionStatus> instanceChangeTaskRunner) {
55 ActionStatus onDeleteInstanceResult = ActionStatus.OK;
56 Iterator<OnComponentInstanceChangeOperation> onDeleteInstIter = onInstanceChangeOperations.iterator();
57 while(onDeleteInstIter.hasNext() && onDeleteInstanceResult == ActionStatus.OK) {
58 onDeleteInstanceResult = instanceChangeTaskRunner.apply(onDeleteInstIter.next());
60 return onDeleteInstanceResult;