--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.serviceutils.srm.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallOutput;
+
+/**
+ * Control interface for ServiceRecoveryRegistry implementation.
+ */
+public interface RegistryControl {
+
+ RecoverOutput recover(RecoverInput input);
+
+ ReinstallOutput reinstall(ReinstallInput input);
+}
<artifactId>tools-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-binding-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-common-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>yang-binding</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>concepts</artifactId>
+ </dependency>
<dependency>
<groupId>com.guicedee.services</groupId>
<artifactId>javax.inject</artifactId>
*/
package org.opendaylight.serviceutils.srm.impl;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.Futures;
import java.util.concurrent.ExecutionException;
+import javax.annotation.PreDestroy;
+import javax.inject.Singleton;
import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.serviceutils.srm.spi.RegistryControl;
+import org.opendaylight.serviceutils.tools.rpc.FutureRpcResults;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev180626.ServiceOps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev180626.service.ops.Services;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev180626.service.ops.ServicesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev180626.service.ops.services.Operations;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev180626.service.ops.services.OperationsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.Recover;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.Reinstall;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.Ofplugin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.ServiceOpRecover;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.ServiceOpReinstall;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Rpc;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * The Utility class for SRM Shell.
- */
-public final class SrmRpcUtils {
- private static final Logger LOG = LoggerFactory.getLogger(SrmRpcUtils.class);
+@Singleton
+@Component(immediate = true, service = RegistryControl.class)
+public final class RegistryControlImpl implements RegistryControl, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(RegistryControlImpl.class);
private static final Boolean REINSTALL_FAILED = Boolean.FALSE;
private static final Boolean REINSTALL_SUCCESS = Boolean.TRUE;
- private SrmRpcUtils() {
- // Hidden on purpose
- }
-
private static final ImmutableMap<EntityNameBase, EntityTypeBase> NAME_TO_TYPE_MAP =
ImmutableMap.<EntityNameBase, EntityTypeBase>builder()
.put(GeniusItm.VALUE, EntityTypeService.VALUE)
.put(NetvirtQosPolicyInstance.VALUE, NetvirtQos.VALUE)
.build();
+ private final DataBroker dataBroker;
+ private final Registration reg;
+
+ @Activate
+ public RegistryControlImpl(@Reference DataBroker dataBroker, @Reference RpcProviderService rpcProvider) {
+ this.dataBroker = requireNonNull(dataBroker);
+ reg = rpcProvider.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(Recover.class, input -> FutureRpcResults.fromListenableFuture(LOG, "recover", input,
+ () -> Futures.immediateFuture(recover(input))).build())
+ .put(Reinstall.class, input -> FutureRpcResults.fromListenableFuture(LOG, "reinstall", input,
+ () -> Futures.immediateFuture(reinstall(input))).build())
+ .build());
+ }
+
+ @Override
+ @Deactivate
+ @PreDestroy
+ public void close() {
+ reg.close();
+ }
- public static RecoverOutput callSrmOp(DataBroker broker, RecoverInput input) {
+ @Override
+ public RecoverOutput recover(RecoverInput input) {
RecoverOutputBuilder outputBuilder = new RecoverOutputBuilder();
if (input.getEntityName() == null) {
outputBuilder.setResponse(RpcFailEntityName.VALUE)
}
Operations operation = opsBuilder.build();
InstanceIdentifier<Operations> opsIid = getInstanceIdentifier(operation, serviceName);
- WriteTransaction tx = broker.newWriteOnlyTransaction();
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, opsIid, operation);
try {
+ // FIXME: we are in RPC invocation path, we should not be blocking here
tx.commit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error writing RecoveryOp to datastore. path:{}, data:{}", opsIid, operation);
return outputBuilder.build();
}
- public static ReinstallOutput callSrmOp(DataBroker broker, ReinstallInput input) {
+ @Override
+ public ReinstallOutput reinstall(ReinstallInput input) {
ReinstallOutputBuilder outputBuilder = new ReinstallOutputBuilder();
if (input.getEntityName() == null) {
outputBuilder.setSuccessful(REINSTALL_FAILED)
.setTriggerOperation(ServiceOpReinstall.VALUE);
Operations operation = opsBuilder.build();
InstanceIdentifier<Operations> opsIid = getInstanceIdentifier(operation, serviceName);
- WriteTransaction tx = broker.newWriteOnlyTransaction();
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, opsIid, operation);
try {
+ // FIXME: we are in RPC invocation path, we should not be blocking here
tx.commit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error writing RecoveryOp to datastore. path:{}, data:{}", opsIid, operation);
+++ /dev/null
-/*
- * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.serviceutils.srm.impl;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.serviceutils.tools.rpc.FutureRpcResults;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.OdlSrmRpcsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallOutput;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.RequireServiceComponentRuntime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Singleton
-@Component(immediate = true, service = OdlSrmRpcsService.class)
-@RequireServiceComponentRuntime
-public final class SrmRpcProvider implements OdlSrmRpcsService, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(SrmRpcProvider.class);
-
- private final DataBroker dataBroker;
- private final Registration reg;
-
- @Inject
- @Activate
- public SrmRpcProvider(@Reference DataBroker dataBroker, @Reference RpcProviderService rpcProvider) {
- this.dataBroker = dataBroker;
- reg = rpcProvider.registerRpcImplementation(OdlSrmRpcsService.class, this);
- }
-
- @Override
- @Deactivate
- @PreDestroy
- public void close() {
- reg.close();
- }
-
- @Override
- public ListenableFuture<RpcResult<RecoverOutput>> recover(RecoverInput input) {
- return FutureRpcResults.fromListenableFuture(LOG, "recover", input,
- () -> Futures.immediateFuture(SrmRpcUtils.callSrmOp(dataBroker, input))).build();
- }
-
- @Override
- public ListenableFuture<RpcResult<ReinstallOutput>> reinstall(ReinstallInput input) {
- return FutureRpcResults.fromListenableFuture(LOG, "reinstall", input,
- () -> Futures.immediateFuture(SrmRpcUtils.callSrmOp(dataBroker, input))).build();
- }
-}
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.eclipse.jdt</groupId>
- <artifactId>org.eclipse.jdt.annotation</artifactId>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>org.eclipse.jdt.annotation</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-binding-api</artifactId>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-binding-api</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-common-api</artifactId>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-common-api</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>yang-binding</artifactId>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>yang-binding</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.serviceutils</groupId>
<artifactId>srm-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-common</artifactId>
- </dependency>
</dependencies>
<build>
*/
package org.opendaylight.serviceutils.srm.shell;
-import java.util.concurrent.Future;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Argument;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.OdlSrmRpcsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverInput;
+import org.opendaylight.serviceutils.srm.spi.RegistryControl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RecoverOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityNameBase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityTypeBase;
-import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.RpcSuccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Argument(index = 2, name = "id", description = "EntityId, optional", required = false, multiValued = false)
private String id;
@Reference
- private OdlSrmRpcsService srmRpcService;
+ private RegistryControl control;
@Override
- public @Nullable Object execute() throws Exception {
- RecoverInput input = getInput();
- if (input == null || srmRpcService == null) {
- // We've already shown the relevant error msg
- return null;
- }
- Future<RpcResult<RecoverOutput>> result = srmRpcService.recover(input);
- RpcResult<RecoverOutput> recoverResult = result.get();
- printResult(recoverResult);
- return null;
- }
-
- @SuppressWarnings("checkstyle:RegexpSinglelineJava")
- private static void printResult(RpcResult<RecoverOutput> recoverResult) {
- var sb = new StringBuilder("");
- if (recoverResult.isSuccessful()) {
- sb.append("RPC call to recover was successful");
- LOG.trace("RPC Result: {}", recoverResult.getResult());
- } else {
- sb.append("RPC Call to recover failed.\n")
- .append("ErrorCode: ").append(recoverResult.getResult().getResponse())
- .append("ErrorMsg: ").append(recoverResult.getResult().getMessage());
- LOG.trace("RPC Result: {}", recoverResult.getResult());
- }
- System.out.println(sb.toString());
- }
-
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
- private @Nullable RecoverInput getInput() {
+ public Object execute() {
if (type == null || name == null) {
return null;
}
- EntityTypeBase entityType = SrmCliUtils.getEntityType(type);
+ var entityType = SrmCliUtils.getEntityType(type);
if (entityType == null) {
System.out.println(SrmCliUtils.getTypeHelp());
return null;
}
- EntityNameBase entityName = SrmCliUtils.getEntityName(entityType, name);
+ var entityName = SrmCliUtils.getEntityName(entityType, name);
if (entityName == null) {
System.out.println(SrmCliUtils.getNameHelp(entityType));
return null;
}
- var inputBuilder = new RecoverInputBuilder()
- .setEntityType(entityType)
- .setEntityName(entityName);
- if (id != null) {
- inputBuilder.setEntityId(id);
+
+ if (control != null) {
+ var inputBuilder = new RecoverInputBuilder()
+ .setEntityType(entityType)
+ .setEntityName(entityName);
+ if (id != null) {
+ inputBuilder.setEntityId(id);
+ }
+ var output = control.recover(inputBuilder.build());
+
+ LOG.trace("RPC Result: {}", output);
+ var response = output.getResponse();
+ if (RpcSuccess.VALUE.equals(response)) {
+ System.out.println("RPC call to recover was successful");
+ } else {
+ System.out.println("RPC call to recover failed.");
+ System.out.println("ErrorCode: " + response);
+ System.out.println("ErrorMsg: " + output.getMessage());
+ }
}
- return inputBuilder.build();
+ return null;
}
}
*/
package org.opendaylight.serviceutils.srm.shell;
-import java.util.concurrent.Future;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Argument;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.OdlSrmRpcsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInput;
+import org.opendaylight.serviceutils.srm.spi.RegistryControl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.rpc.rev180626.ReinstallOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityNameBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.EntityTypeService;
-import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
required = false, multiValued = false)
private String name;
@Reference
- private OdlSrmRpcsService srmRpcService;
+ private RegistryControl control;
@Override
- public @Nullable Object execute() throws Exception {
- ReinstallInput input = getInput();
- if (input == null || srmRpcService == null) {
- return null;
- }
- Future<RpcResult<ReinstallOutput>> result = srmRpcService.reinstall(input);
- RpcResult<ReinstallOutput> reinstallResult = result.get();
- printResult(reinstallResult);
- return null;
- }
-
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
- private static void printResult(RpcResult<ReinstallOutput> reinstallResult) {
- var sb = new StringBuilder("");
- if (reinstallResult.isSuccessful()) {
- sb.append("RPC call to reinstall was successful");
- LOG.trace("RPC Result: {}", reinstallResult.getResult());
- } else {
- sb.append("RPC Call to reinstall failed.\n")
- .append("ErrorMsg: ").append(reinstallResult.getResult().getMessage());
- LOG.trace("RPC Result: {}", reinstallResult.getResult());
- }
- System.out.println(sb.toString());
- }
-
- @SuppressWarnings("checkstyle:RegexpSinglelineJava")
- private @Nullable ReinstallInput getInput() {
- EntityNameBase entityName = SrmCliUtils.getEntityName(ENTITY_TYPE, name);
+ public Object execute() {
+ var entityName = SrmCliUtils.getEntityName(ENTITY_TYPE, name);
if (entityName == null) {
System.out.println(SrmCliUtils.getNameHelp(ENTITY_TYPE));
return null;
}
- return new ReinstallInputBuilder()
- .setEntityType(ENTITY_TYPE)
- .setEntityName(entityName)
- .build();
+
+ if (control != null) {
+ var output = control.reinstall(new ReinstallInputBuilder()
+ .setEntityType(ENTITY_TYPE)
+ .setEntityName(entityName)
+ .build());
+
+ LOG.trace("RPC Result: {}", output);
+ if (Boolean.TRUE.equals(output.getSuccessful())) {
+ System.out.println("RPC call to reinstall was successful");
+ } else {
+ System.out.println("RPC Call to reinstall failed.");
+ System.out.println("ErrorMsg: " + output.getMessage());
+ }
+ }
+ return null;
}
}