Search in sources :

Example 1 with OperationsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder in project genius by opendaylight.

the class SrmRpcUtils method callSrmOp.

public static ReinstallOutput callSrmOp(DataBroker broker, ReinstallInput input) {
    ReinstallOutputBuilder outputBuilder = new ReinstallOutputBuilder();
    if (input.getEntityName() == null) {
        outputBuilder.setSuccessful(REINSTALL_FAILED).setMessage("EntityName is null");
        return outputBuilder.build();
    }
    if (input.getEntityType() == null) {
        outputBuilder.setSuccessful(REINSTALL_FAILED).setMessage(String.format("EntityType for %s can't be null", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    }
    if (!EntityTypeService.class.equals(input.getEntityType())) {
        outputBuilder.setSuccessful(REINSTALL_FAILED).setMessage(String.format("EntityType is %s, Reinstall is only for EntityTypeService", input.getEntityType()));
        return outputBuilder.build();
    }
    Class<? extends EntityNameBase> serviceName = NAME_TO_SERVICE_MAP.get(input.getEntityName());
    if (serviceName == null) {
        outputBuilder.setSuccessful(REINSTALL_FAILED).setMessage(String.format("EntityName %s has no matching service", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    }
    Class<? extends EntityTypeBase> entityType = NAME_TO_TYPE_MAP.get(input.getEntityName());
    if (entityType == null || !input.getEntityType().equals(entityType)) {
        outputBuilder.setSuccessful(REINSTALL_FAILED).setMessage(String.format("EntityName %s doesn't match with EntityType %s", input.getEntityName().getSimpleName(), entityType));
        return outputBuilder.build();
    }
    OperationsBuilder opsBuilder = new OperationsBuilder().setEntityName(input.getEntityName()).setEntityType(entityType).setTriggerOperation(ServiceOpReinstall.class);
    Operations operation = opsBuilder.build();
    InstanceIdentifier<Operations> opsIid = getInstanceIdentifier(operation, serviceName);
    WriteTransaction tx = broker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, opsIid, operation, CREATE_MISSING_PARENT);
    try {
        tx.submit().get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Error writing RecoveryOp to datastore. path:{}, data:{}", opsIid, operation);
        outputBuilder.setSuccessful(REINSTALL_FAILED).setMessage(e.getMessage());
        return outputBuilder.build();
    }
    outputBuilder.setSuccessful(REINSTALL_SUCCESS).setMessage("Recovery operation successfully triggered");
    return outputBuilder.build();
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ReinstallOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.ReinstallOutputBuilder) OperationsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder) EntityTypeService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.EntityTypeService) ExecutionException(java.util.concurrent.ExecutionException) Operations(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations)

Example 2 with OperationsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder in project genius by opendaylight.

the class SrmRpcUtils method callSrmOp.

public static RecoverOutput callSrmOp(DataBroker broker, RecoverInput input) {
    RecoverOutputBuilder outputBuilder = new RecoverOutputBuilder();
    if (input.getEntityName() == null) {
        outputBuilder.setResponse(RpcFailEntityName.class).setMessage("EntityName is null");
        return outputBuilder.build();
    }
    if (input.getEntityType() == null) {
        outputBuilder.setResponse(RpcFailEntityType.class).setMessage(String.format("EntityType for %s can't be null", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    }
    String entityId;
    if (EntityTypeInstance.class.equals(input.getEntityType()) && input.getEntityId() == null) {
        outputBuilder.setResponse(RpcFailEntityId.class).setMessage(String.format("EntityId can't be null for %s", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    } else {
        entityId = input.getEntityId();
    }
    Class<? extends EntityNameBase> serviceName = NAME_TO_SERVICE_MAP.get(input.getEntityName());
    if (serviceName == null) {
        outputBuilder.setResponse(RpcFailEntityName.class).setMessage(String.format("EntityName %s has no matching service", input.getEntityName().getSimpleName()));
        return outputBuilder.build();
    }
    Class<? extends EntityTypeBase> entityType = NAME_TO_TYPE_MAP.get(input.getEntityName());
    if (entityType == null || !input.getEntityType().equals(entityType)) {
        outputBuilder.setResponse(RpcFailEntityType.class).setMessage(String.format("EntityName %s doesn't match with EntityType %s", input.getEntityName().getSimpleName(), entityType));
        return outputBuilder.build();
    }
    OperationsBuilder opsBuilder = new OperationsBuilder().setEntityName(input.getEntityName()).setEntityType(entityType).setTriggerOperation(ServiceOpRecover.class);
    if (entityId != null) {
        opsBuilder.setEntityId(entityId);
    }
    Operations operation = opsBuilder.build();
    InstanceIdentifier<Operations> opsIid = getInstanceIdentifier(operation, serviceName);
    WriteTransaction tx = broker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, opsIid, operation, CREATE_MISSING_PARENT);
    try {
        tx.submit().get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Error writing RecoveryOp to datastore. path:{}, data:{}", opsIid, operation);
        outputBuilder.setResponse(RpcFailUnknown.class).setMessage(e.getMessage());
        return outputBuilder.build();
    }
    outputBuilder.setResponse(RpcSuccess.class).setMessage("Recovery operation successfully triggered");
    return outputBuilder.build();
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) RpcFailEntityId(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityId) RpcFailEntityType(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityType) RpcSuccess(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcSuccess) RecoverOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RecoverOutputBuilder) OperationsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder) RpcFailEntityName(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityName) EntityTypeInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.EntityTypeInstance) ExecutionException(java.util.concurrent.ExecutionException) Operations(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 Operations (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations)2 OperationsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder)2 RecoverOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RecoverOutputBuilder)1 ReinstallOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.ReinstallOutputBuilder)1 RpcFailEntityId (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityId)1 RpcFailEntityName (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityName)1 RpcFailEntityType (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcFailEntityType)1 RpcSuccess (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RpcSuccess)1 EntityTypeInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.EntityTypeInstance)1 EntityTypeService (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.types.rev170711.EntityTypeService)1