aboutsummaryrefslogtreecommitdiffstats
path: root/appc-provider/appc-provider-bundle/src/main
diff options
context:
space:
mode:
authorHao Kuang <Hao.Kuang@amdocs.com>2017-09-27 21:26:02 +0000
committerPatrick Brady <pb071s@att.com>2017-09-27 22:08:36 +0000
commit78f459993575bcab672898610ec281674ccaebc3 (patch)
treedb975df296b03cdc0201f75e3d5c596789e722d2 /appc-provider/appc-provider-bundle/src/main
parentcf896d8cff45754a3bdb00f2f277eef3a5ae0cd2 (diff)
Add Junit test for appc-provider bundle
1. add junite test for appc-provider bundle to increase sonar test converage. 2. move test files of appc-dg-util under java folder. Issue-Id: APPC-229 Change-Id: I37620a820eb99aecb7fe91974826b4ef2e5d428a Signed-off-by: Hao Kuang <Hao.Kuang@amdocs.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/main')
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProvider.java108
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProviderLcm.java70
2 files changed, 81 insertions, 97 deletions
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProvider.java b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProvider.java
index 9989bddbc..2fd3b4f8d 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProvider.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/openecomp/appc/provider/AppcProvider.java
@@ -9,65 +9,53 @@
* 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.
- *
+ *
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
package org.openecomp.appc.provider;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.google.common.util.concurrent.Futures;
-import org.json.JSONObject;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.*;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateOutput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateOutput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.ModifyConfigInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.ModifyConfigOutput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildOutput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartOutput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.SnapshotInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.SnapshotOutput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.VmstatuscheckInput;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.VmstatuscheckOutput;
import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.common.request.header.CommonRequestHeader;
-import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.responseattributes.StatusBuilder;
-import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.responseheader.ResponseHeaderBuilder;
-import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.vnf.resource.VnfResource;
import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.config.payload.ConfigPayload;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.vnf.resource.VnfResource;
import org.opendaylight.yangtools.yang.common.RpcResult;
-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.executor.objects.LCMCommandStatus;
-import org.openecomp.appc.executor.objects.Params;
import org.openecomp.appc.i18n.Msg;
-import org.openecomp.appc.provider.lcm.util.RequestInputBuilder;
-import org.openecomp.appc.provider.lcm.util.ValidationService;
import org.openecomp.appc.provider.topology.TopologyService;
-import org.openecomp.appc.requesthandler.RequestHandler;
-import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
-import org.openecomp.appc.requesthandler.objects.RequestHandlerOutput;
-import com.att.eelf.configuration.EELFLogger;
-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.ServiceReference;
-import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.status.Status;
-import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.Action;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.TimeZone;
+
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -110,8 +98,6 @@ public class AppcProvider implements AutoCloseable, AppcProviderService {
private final ExecutorService executor;
- private ListenerRegistration<DataChangeListener> dclServices;
-
/**
* The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
* subscribe for changes to data under a given branch of the tree.
@@ -181,14 +167,13 @@ public class AppcProvider implements AutoCloseable, AppcProviderService {
logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
}
+ public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput input) {
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ ConfigPayload data = input.getConfigPayload();
+ RpcResult<ModifyConfigOutput> result = getTopologyService().modifyConfig(hdr, data);
+ return Futures.immediateFuture(result);
+ }
-public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput input){
- CommonRequestHeader hdr = input.getCommonRequestHeader();
- ConfigPayload data = input.getConfigPayload();
- TopologyService topology = new TopologyService(this);
- RpcResult<ModifyConfigOutput> result = topology.modifyConfig(hdr, data);
- return Futures.immediateFuture(result);
-}
/**
* Rebuilds a specific VNF
*
@@ -200,8 +185,7 @@ public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput inpu
CommonRequestHeader hdr = input.getCommonRequestHeader();
VnfResource vnf = input.getVnfResource();
- TopologyService topology = new TopologyService(this);
- RpcResult<RebuildOutput> result = topology.rebuild(hdr, vnf);
+ RpcResult<RebuildOutput> result = getTopologyService().rebuild(hdr, vnf);
return Futures.immediateFuture(result);
}
@@ -215,8 +199,7 @@ public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput inpu
CommonRequestHeader hdr = input.getCommonRequestHeader();
VnfResource vnf = input.getVnfResource();
- TopologyService topology = new TopologyService(this);
- RpcResult<RestartOutput> result = topology.restart(hdr, vnf);
+ RpcResult<RestartOutput> result = getTopologyService().restart(hdr, vnf);
return Futures.immediateFuture(result);
}
@@ -230,8 +213,7 @@ public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput inpu
CommonRequestHeader hdr = input.getCommonRequestHeader();
VnfResource vnf = input.getVnfResource();
- TopologyService topology = new TopologyService(this);
- RpcResult<MigrateOutput> result = topology.migrate(hdr, vnf);
+ RpcResult<MigrateOutput> result = getTopologyService().migrate(hdr, vnf);
return Futures.immediateFuture(result);
}
@@ -242,10 +224,7 @@ public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput inpu
*/
@Override
public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
- CommonRequestHeader hdr = input.getCommonRequestHeader();
- VnfResource vnf = input.getVnfResource();
- TopologyService topology = new TopologyService(this);
return null;
}
@@ -259,23 +238,24 @@ public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput inpu
CommonRequestHeader hdr = input.getCommonRequestHeader();
VnfResource vnf = input.getVnfResource();
- TopologyService topology = new TopologyService(this);
- RpcResult<SnapshotOutput> result = topology.snapshot(hdr, vnf);
+ RpcResult<SnapshotOutput> result = getTopologyService().snapshot(hdr, vnf);
return Futures.immediateFuture(result);
}
-
-
+
/**
* Checks status of a VM
- */
+ */
@Override
public Future<RpcResult<VmstatuscheckOutput>> vmstatuscheck(VmstatuscheckInput input) {
- CommonRequestHeader hdr = input.getCommonRequestHeader();
- VnfResource vnf = input.getVnfResource();
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ VnfResource vnf = input.getVnfResource();
- TopologyService topology = new TopologyService(this);
- RpcResult<VmstatuscheckOutput> result = topology.vmstatuscheck(hdr, vnf);
- return Futures.immediateFuture(result);
- }
+ TopologyService topology = getTopologyService();
+ RpcResult<VmstatuscheckOutput> result = getTopologyService().vmstatuscheck(hdr, vnf);
+ return Futures.immediateFuture(result);
+ }
-}
+ TopologyService getTopologyService() {
+ return new TopologyService(this);
+ }
+} \ No newline at end of file
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 370ed5287..b13a74201 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
@@ -503,25 +503,6 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
return buildStatus(statusCode, statusMessage);
}
- private RequestHandlerOutput executeRequest(RequestHandlerInput request){
- RequestHandler handler = getRequestHandler();
- RequestHandlerOutput requestHandlerOutput;
- if (handler != null) {
- try {
- requestHandlerOutput = handler.handleRequest(request);
- } catch (Exception e) {
- logger.info("UNEXPECTED FAILURE while executing " + request.getRequestContext().getAction().name());
- requestHandlerOutput = createErrorRequestHandlerObj(request,
- LCMCommandStatus.UNEXPECTED_ERROR, Msg.EXCEPTION_CALLING_DG, e);
- }
- } else {
- String errorMsg = "LCM request cannot be processed at the moment because APPC isn't running";
- requestHandlerOutput = createErrorRequestHandlerObj(request,
- LCMCommandStatus.REJECTED, Msg.REQUEST_HANDLER_UNAVAILABLE, new APPCException(errorMsg));
- }
- return requestHandlerOutput;
- }
-
private RequestHandlerOutput createErrorRequestHandlerObj(RequestHandlerInput request,
LCMCommandStatus cmdStatus,
Msg msg,
@@ -1006,33 +987,39 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<CheckLockOutput>> checkLock(CheckLockInput input) {
logger.debug("Input received : " + input.toString());
CheckLockOutputBuilder outputBuilder = new CheckLockOutputBuilder();
- String action = Action.CheckLock.toString() ;
+ String action = Action.CheckLock.toString();
String rpcName = Action.CheckLock.name().toLowerCase();
- RequestHandlerOutput requestHandlerOutput=null;
- Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
- if(null == status) {
+ RequestHandlerOutput requestHandlerOutput = null;
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(),
+ input.getAction(), action);
+ if (null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action).rpcName(rpcName).build();
- requestHandlerOutput=executeRequest(request);
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input
+ .getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action)
+ .rpcName(rpcName).build();
+ requestHandlerOutput = executeRequest(request);
status = buildStatusWithDispatcherOutput(requestHandlerOutput);
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
status = buildParsingErrorStatus(e);
LoggingUtils.logErrorMessage(
- LoggingConstants.TargetNames.APPC_PROVIDER,
- String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
- this.getClass().getName());
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
}
}
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
- if(requestHandlerOutput.getResponseContext().getStatus().getCode() == 400) {
- outputBuilder.setLocked(CheckLockOutput.Locked.valueOf(requestHandlerOutput.getResponseContext().getAdditionalContext().get("locked").toUpperCase()));
+ if (requestHandlerOutput != null && requestHandlerOutput.getResponseContext().getStatus().getCode() == 400) {
+ outputBuilder.setLocked(CheckLockOutput.Locked.valueOf(requestHandlerOutput.getResponseContext()
+ .getAdditionalContext().get("locked").toUpperCase()));
}
- RpcResult<CheckLockOutput> result = RpcResultBuilder.<CheckLockOutput> status(true).withResult(outputBuilder.build()).build();
+ RpcResult<CheckLockOutput> result = RpcResultBuilder.<CheckLockOutput>status(true)
+ .withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@@ -1191,5 +1178,22 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
.toLowerCase();
}
-
+ RequestHandlerOutput executeRequest(RequestHandlerInput request){
+ RequestHandler handler = getRequestHandler();
+ RequestHandlerOutput requestHandlerOutput;
+ if (handler != null) {
+ try {
+ requestHandlerOutput = handler.handleRequest(request);
+ } catch (Exception e) {
+ logger.info("UNEXPECTED FAILURE while executing " + request.getRequestContext().getAction().name());
+ requestHandlerOutput = createErrorRequestHandlerObj(request,
+ LCMCommandStatus.UNEXPECTED_ERROR, Msg.EXCEPTION_CALLING_DG, e);
+ }
+ } else {
+ String errorMsg = "LCM request cannot be processed at the moment because APPC isn't running";
+ requestHandlerOutput = createErrorRequestHandlerObj(request,
+ LCMCommandStatus.REJECTED, Msg.REQUEST_HANDLER_UNAVAILABLE, new APPCException(errorMsg));
+ }
+ return requestHandlerOutput;
+ }
}