+
+ @Override
+ public Future<RpcResult<ServiceStateModifyOutput>> serviceStateModify(ServiceStateModifyInput input) {
+ LOG.info("RPC service state modify received");
+ String servicename = input.getServiceName();
+ String message = "";
+ String responseCode = "500";
+ if (servicename != null) {
+ Services service = readServiceList(servicename);
+ if (service != null) {
+ LOG.info("Modify '{}' Service state", servicename);
+ WriteTransaction writeTx = db.newWriteOnlyTransaction();
+ String result = null;
+ Future<Void> future = null;
+ InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
+ new ServicesKey(servicename));
+ ServicesBuilder modifyService = new ServicesBuilder(service);
+ modifyService.setOperationalState(State.OutOfService);
+ writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, modifyService.build());
+ future = writeTx.submit();
+ try {
+ Futures.getChecked(future, ExecutionException.class);
+ } catch (ExecutionException e) {
+ LOG.info("Failed to {} service from Service List", action);
+ result = "Failed to " + action + " service from Service List";
+ }
+ if (result == null) {
+ responseCode = "200";
+ message = "Service state modified !";
+ }
+ } else {
+ message = "Service not present in datastore ! ";
+ }
+ } else {
+ message = "servicename not set in ServiceStateModifyInput";
+ }
+ ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
+ .setAckFinalIndicator("Yes")
+ .setResponseCode(responseCode)
+ .setResponseMessage(message)
+ .build();
+ ServiceStateModifyOutput output = new ServiceStateModifyOutputBuilder()
+ .setConfigurationResponseCommon(configurationResponseCommon)
+ .build();
+ return RpcResultBuilder.success(output).buildFuture();
+ }