/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@Override
public boolean deployRappInstance(Rapp rapp, RappInstance rappInstance) {
logger.debug("Deploying SME functions for RappInstance {}", rappInstance.getRappInstanceId());
- if (createProviderDomain(rapp, rappInstance) && createPublishApi(rapp, rappInstance) && createInvoker(rapp,
- rappInstance)) {
- rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYED);
- return true;
+ if (rappInstance.isSMEEnabled()) {
+ if ((rappInstance.getSme().getProviderFunction() == null || createProviderDomain(rapp, rappInstance)) && (
+ rappInstance.getSme().getServiceApis() == null || createPublishApi(rapp, rappInstance)) && (
+ rappInstance.getSme().getInvokers() == null || createInvoker(rapp, rappInstance))) {
+ rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYED);
+ return true;
+ }
+ rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYFAILED);
+ rappInstance.setReason("Unable to deploy SME");
+ return false;
}
- rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEDEPLOYFAILED);
- rappInstance.setReason("Unable to deploy SME");
- return false;
+ return true;
}
@Override
public boolean undeployRappInstance(Rapp rapp, RappInstance rappInstance) {
logger.debug("Undeploying SME functions for Rapp {}", rapp.getName());
- try {
- rappInstance.getSme().getInvokerIds().forEach(this::deleteInvoker);
- rappInstance.getSme().getServiceApiIds()
- .forEach(s -> deletePublishApi(s, rappInstance.getSme().getApfId()));
- rappInstance.getSme().getProviderFunctionIds().forEach(this::deleteProviderFunc);
- rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYED);
- return true;
- } catch (Exception e) {
- logger.warn("Failed to Undeploy SME functions for Rapp {}", rapp.getName(), e);
+ if (rappInstance.isSMEEnabled()) {
+ try {
+ Optional.ofNullable(rappInstance.getSme().getInvokerIds())
+ .ifPresent(invokerList -> invokerList.forEach(this::deleteInvoker));
+ Optional.ofNullable(rappInstance.getSme().getServiceApiIds()).ifPresent(
+ serviceApiList -> serviceApiList.forEach(
+ s -> deletePublishApi(s, rappInstance.getSme().getApfId())));
+ Optional.ofNullable(rappInstance.getSme().getProviderFunctionIds())
+ .ifPresent(providerList -> providerList.forEach(this::deleteProviderFunc));
+ rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYED);
+ return true;
+ } catch (Exception e) {
+ logger.warn("Failed to Undeploy SME functions for Rapp {}", rapp.getName(), e);
+ }
+ rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYFAILED);
+ rappInstance.setReason("Unable to undeploy SME");
+ return false;
}
- rappInstanceStateMachine.sendRappInstanceEvent(rappInstance, RappEvent.SMEUNDEPLOYFAILED);
- rappInstance.setReason("Unable to undeploy SME");
- return false;
+ return true;
}
@Override
boolean createInvoker(Rapp rapp, RappInstance rappInstance) {
logger.debug("Creating provider domain for Rapp {}", rapp.getName());
try {
- String invokerPayload = rappCsarConfigurationHandler.getSmeInvokerPayload(rapp, rappInstance.getSme());
+ String invokerPayload = rappCsarConfigurationHandler.getSmeInvokerPayload(rapp, rappInstance);
if (invokerPayload != null) {
List<APIInvokerEnrolmentDetails> apiInvokerEnrolmentDetails =
objectMapper.readValue(invokerPayload, new TypeReference<>() { });