diff options
Diffstat (limited to 'controlloop/common/actors/actor.vfc/src')
2 files changed, 95 insertions, 0 deletions
diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java new file mode 100644 index 000000000..ffada0a81 --- /dev/null +++ b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017 Intel Corp. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.vfc; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.vfc.VFCRequest; +import org.onap.policy.vfc.VFCHealRequest; +import org.onap.policy.vfc.VFCHealAdditionalParams; +import org.onap.policy.vfc.VFCHealActionVmInfo; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.policy.Policy; + +import org.onap.policy.controlloop.actorServiceProvider.spi.Actor; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + + +public class VFCActorServiceProvider implements Actor { + + private static final ImmutableList<String> recipes = ImmutableList.of("Restart"); + private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>() + .put("Restart", ImmutableList.of("VM")) + .build(); + + @Override + public String actor() { + return "VFC"; + } + + @Override + public List<String> recipes() { + return ImmutableList.copyOf(recipes); + } + + @Override + public List<String> recipeTargets(String recipe) { + return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); + } + + @Override + public List<String> recipePayloads(String recipe) { + return Collections.emptyList(); + } + + public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) { + + // Construct an VFC request + VFCRequest request = new VFCRequest(); + // TODO: Verify service-instance-id is part of onset event + request.nsInstanceId = onset.AAI.get("service-instance.service-instance-id"); + request.healRequest = new VFCHealRequest(); + request.healRequest.vnfInstanceId = onset.AAI.get("generic-vnf.vnf-id"); + request.healRequest.cause = operation.message; + + request.healRequest.additionalParams = new VFCHealAdditionalParams(); + switch (policy.getRecipe()) { + case "Restart": + // TODO: check target?? + request.healRequest.additionalParams.action = "restartvm"; + request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo(); + // TODO: Verify vserver-id and vserver-name is part of onset event + request.healRequest.additionalParams.actionInfo.vmid = onset.AAI.get("vserver.vserver-id"); + request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name"); + break; + default: + //TODO: default + break; + } + return request; + } + + +} diff --git a/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor new file mode 100644 index 000000000..3ccac9949 --- /dev/null +++ b/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor @@ -0,0 +1 @@ +org.onap.policy.controlloop.actor.vfc.APPCActorServiceProvider |