2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2023 Nordix Foundation. All rights reserved.
4 * ===============================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END========================================================================
19 package com.oransc.rappmanager.acm.service;
22 import com.oransc.rappmanager.acm.configuration.ACMConfiguration;
23 import java.nio.file.Files;
24 import java.nio.file.Path;
25 import java.util.concurrent.TimeUnit;
26 import lombok.RequiredArgsConstructor;
27 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
28 import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
29 import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.context.SmartLifecycle;
33 import org.springframework.stereotype.Service;
36 @RequiredArgsConstructor
37 public class AutomationCompositionLifeCycleManager implements SmartLifecycle {
39 Logger logger = LoggerFactory.getLogger(AutomationCompositionLifeCycleManager.class);
40 private final ACMConfiguration acmConfiguration;
41 private final AcmDeployer acmDeployer;
42 private boolean running;
46 logger.info("Initializing automation Composition");
48 String compositionPayload = Files.readString(Path.of(acmConfiguration.getCompositionDefinitionLocation()));
49 CommissioningResponse commissioningResponse =
50 acmDeployer.createComposition(compositionPayload);
51 if (commissioningResponse != null && commissioningResponse.getCompositionId() != null) {
52 logger.info("Priming automation Composition");
53 acmDeployer.primeACMComposition(commissioningResponse.getCompositionId(),
55 for (int i = 0; i < acmConfiguration.getMaxRetries(); i++) {
56 logger.debug("Composition priming check {}", i + 1);
57 if (acmDeployer.isCompositionStateEquals(commissioningResponse.getCompositionId(),
58 AcTypeState.PRIMED)) {
59 logger.info("Composition {} is primed", commissioningResponse.getCompositionId());
63 TimeUnit.SECONDS.sleep(acmConfiguration.getRetryInterval());
67 logger.error("Failed to create automation composition");
69 } catch (Exception e) {
70 logger.error("Failed to create automation composition", e);
76 logger.info("Depriming automation Composition");
79 acmDeployer.primeACMComposition(acmDeployer.getCompositionId(),
81 for (int i = 0; i < acmConfiguration.getMaxRetries(); i++) {
82 logger.debug("Composition depriming check {}", i + 1);
83 if (acmDeployer.isCompositionStateEquals(
84 acmDeployer.getCompositionId(), AcTypeState.COMMISSIONED)) {
85 logger.info("Composition {} is deprimed", acmDeployer.getCompositionId());
86 logger.info("Deleting automation Composition");
87 acmDeployer.deleteComposition(acmDeployer.getCompositionId());
91 TimeUnit.SECONDS.sleep(acmConfiguration.getRetryInterval());
94 } catch (Exception e) {
95 logger.error("Failed to cleanup automation composition");
101 public boolean isRunning() {