From 38713207b817ed4700f630748c681116338d32f0 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Fri, 28 Jul 2017 11:29:23 -0700 Subject: Merging in bug fixes Change-Id: I85da90b9ba0d03149f42035a820c76ef0285e413 Signed-off-by: Patrick Brady Issue: APPC-100 --- .../openecomp/appc/provider/AppcProviderLcm.java | 28 ++++++++++++++-------- .../provider/lcm/util/RequestInputBuilder.java | 12 ++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'appc-provider/appc-provider-bundle/src/main/java/org/openecomp') diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProviderLcm.java b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProviderLcm.java index de77c8ea6..90097aea8 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProviderLcm.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProviderLcm.java @@ -25,6 +25,7 @@ package org.openecomp.appc.provider; import java.text.ParseException; +import java.util.Collection; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -42,6 +43,7 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.openecomp.appc.Constants; import org.openecomp.appc.configuration.Configuration; import org.openecomp.appc.configuration.ConfigurationFactory; +import org.openecomp.appc.domainmodel.lcm.ActionLevel; import org.openecomp.appc.domainmodel.lcm.ResponseContext; import org.openecomp.appc.domainmodel.lcm.RuntimeContext; import org.openecomp.appc.executor.objects.LCMCommandStatus; @@ -59,6 +61,7 @@ import com.att.eelf.configuration.EELFManager; import com.att.eelf.i18n.EELFResourceManager; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; import com.google.common.util.concurrent.Futures; @@ -179,7 +182,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService { /** * Restarts a specific VNF * - * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.AppcProviderLcmService#restart(RestartInput) + * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.AppcProviderLcmService#restart(RestartInput) */ @Override public Future> restart(RestartInput input) { @@ -402,7 +405,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService { private RequestHandlerOutput executeRequest(RequestHandlerInput request){ - RequestHandler handler = getRequestHandler(); + RequestHandler handler = getRequestHandler(request.getRequestContext().getActionLevel()); RequestHandlerOutput requestHandlerOutput; try { requestHandlerOutput = handler.handleRequest(request); @@ -432,16 +435,21 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService { return requestHandlerOutput; } - private RequestHandler getRequestHandler(){ + private RequestHandler getRequestHandler(ActionLevel actionLevel){ RequestHandler handler ; final BundleContext context = FrameworkUtil.getBundle(RequestHandler.class).getBundleContext(); - final ServiceReference reference = context.getServiceReference(RequestHandler.class.getName()); - - if (reference != null) { - handler = (RequestHandler) context.getService(reference); - } else { - logger.error("Cannot find service reference for " + RequestHandler.class.getName()); - throw new RuntimeException(); + String filter = "(level=" + actionLevel.name() + ")"; + try { + Collection> serviceReferences = context.getServiceReferences(RequestHandler.class, filter); + if (serviceReferences.size() != 1) { + logger.error("Cannot find service reference for " + RequestHandler.class.getName()); + throw new RuntimeException(); + } + ServiceReference serviceReference = serviceReferences.iterator().next(); + handler = context.getService(serviceReference); + } catch (InvalidSyntaxException e) { + logger.error("Cannot find service reference for " + RequestHandler.class.getName() + ": Invalid Syntax " + filter, e); + throw new RuntimeException(e); } return handler ; } diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java index 0c4fc7341..495fa82a6 100644 --- a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java +++ b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/lcm/util/RequestInputBuilder.java @@ -28,11 +28,13 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.TimeZone; +import org.apache.commons.lang.StringUtils; import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.Payload; import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.action.identifiers.ActionIdentifiers; import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.CommonHeader; import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags; import org.openecomp.appc.domainmodel.lcm.Flags.Mode; +import org.openecomp.appc.domainmodel.lcm.ActionLevel; import org.openecomp.appc.domainmodel.lcm.RequestContext; import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.requesthandler.objects.RequestHandlerInput; @@ -139,11 +141,21 @@ public class RequestInputBuilder { actionIds.setvServerId(actionIdentifiers.getVserverId()); actionIds.setVnfId(actionIdentifiers.getVnfId()); this.requestContext.setActionIdentifiers(actionIds); + + ActionLevel actionLevel = readActionLevel(actionIds); + this.requestContext.setActionLevel(actionLevel); return this; }else{ throw new ParseException("Missing action identifier" , 0); } } + private ActionLevel readActionLevel(org.openecomp.appc.domainmodel.lcm.ActionIdentifiers actionIds) { + if(!StringUtils.isEmpty(actionIds.getVserverId())){ + return ActionLevel.VM; + } + return ActionLevel.VNF; + } + } -- cgit 1.2.3-korg