Search in sources :

Example 1 with EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName 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 EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName in project genius by opendaylight.

the class RecoverCommand method getInput.

private RecoverInput getInput() {
    if (type == null || name == null) {
        return null;
    }
    Class<? extends EntityTypeBase> entityType = SrmCliUtils.getEntityType(type);
    if (entityType == null) {
        session.getConsole().println(SrmCliUtils.getTypeHelp());
        return null;
    }
    Class<? extends EntityNameBase> entityName = SrmCliUtils.getEntityName(entityType, name);
    if (entityName == null) {
        session.getConsole().println(SrmCliUtils.getNameHelp(entityType));
        return null;
    }
    RecoverInputBuilder inputBuilder = new RecoverInputBuilder();
    inputBuilder.setEntityType(entityType);
    inputBuilder.setEntityName(entityName);
    if (id != null) {
        inputBuilder.setEntityId(id);
    }
    return inputBuilder.build();
}
Also used : RecoverInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.RecoverInputBuilder)

Example 3 with EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName in project genius by opendaylight.

the class ReinstallCommand method getInput.

private ReinstallInput getInput() {
    Class<? extends EntityNameBase> entityName = SrmCliUtils.getEntityName(entityType, name);
    if (entityName == null) {
        session.getConsole().println(SrmCliUtils.getNameHelp(entityType));
        return null;
    }
    ReinstallInputBuilder inputBuilder = new ReinstallInputBuilder();
    inputBuilder.setEntityType(entityType);
    inputBuilder.setEntityName(entityName);
    return inputBuilder.build();
}
Also used : ReinstallInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.rpcs.rev170711.ReinstallInputBuilder)

Example 4 with EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName in project controller by opendaylight.

the class AkkaEntityOwnershipServiceTest method testEntityRetrievalWithYiid.

@Test
public void testEntityRetrievalWithYiid() throws Exception {
    final YangInstanceIdentifier entityId = YangInstanceIdentifier.create(new NodeIdentifier(NetworkTopology.QNAME), new NodeIdentifier(Topology.QNAME), NodeIdentifierWithPredicates.of(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), "test"), new NodeIdentifier(Node.QNAME), NodeIdentifierWithPredicates.of(Node.QNAME, QName.create(Node.QNAME, "node-id"), "test://test-node"));
    final DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
    final DOMEntityOwnershipCandidateRegistration reg = service.registerCandidate(entity);
    verifyEntityOwnershipCandidateRegistration(entity, reg);
    verifyEntityCandidateRegistered(ENTITY_TYPE, entityId, "member-1");
    RpcResult<GetEntityOutput> getEntityResult = service.getEntity(new GetEntityInputBuilder().setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId))).setType(new EntityType(ENTITY_TYPE)).build()).get();
    assertEquals(getEntityResult.getResult().getOwnerNode().getValue(), "member-1");
    assertEquals(getEntityResult.getResult().getCandidateNodes().get(0).getValue(), "member-1");
    // we should not be able to retrieve the entity when using string
    final String entityPathEncoded = "/network-topology:network-topology/topology[topology-id='test']/node[node-id='test://test-node']";
    getEntityResult = service.getEntity(new GetEntityInputBuilder().setName(new EntityName(entityPathEncoded)).setType(new EntityType(ENTITY_TYPE)).build()).get();
    assertNull(getEntityResult.getResult().getOwnerNode());
    assertTrue(getEntityResult.getResult().getCandidateNodes().isEmpty());
    final GetEntitiesOutput getEntitiesResult = service.getEntities(new GetEntitiesInputBuilder().build()).get().getResult();
    assertEquals(getEntitiesResult.getEntities().size(), 1);
    assertTrue(getEntitiesResult.getEntities().get(new EntitiesKey(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)), new EntityType(ENTITY_TYPE))).getCandidateNodes().contains(new NodeName("member-1")));
    assertTrue(getEntitiesResult.getEntities().get(new EntitiesKey(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)), new EntityType(ENTITY_TYPE))).getOwnerNode().getValue().equals("member-1"));
    final GetEntityOwnerOutput getOwnerResult = service.getEntityOwner(new GetEntityOwnerInputBuilder().setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId))).setType(new EntityType(ENTITY_TYPE)).build()).get().getResult();
    assertEquals(getOwnerResult.getOwnerNode().getValue(), "member-1");
}
Also used : GetEntityOwnerInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerInputBuilder) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) EntityName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName) NodeName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) EntitiesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.get.entities.output.EntitiesKey) GetEntityOwnerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerOutput) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) GetEntityInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityInputBuilder) EntityType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityType) GetEntityOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput) GetEntitiesInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesInputBuilder) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) GetEntitiesOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutput) Test(org.junit.Test)

Example 5 with EntityName

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName in project controller by opendaylight.

the class EntityRpcHandlerTest method testEntityRetrievalWithUnavailableSupervisor.

/*
     * Tests entity rpcs handled both by the owner supervisor(service1) and with an idle supervisor(falling
     * back to distributed-data in an inactive datacenter). This covers both the available cases, datacenters and case
     * in which the node with active akka-singleton is shutdown and another one takes over.
     */
@Test
public void testEntityRetrievalWithUnavailableSupervisor() throws Exception {
    final YangInstanceIdentifier entityId = YangInstanceIdentifier.create(new NodeIdentifier(NetworkTopology.QNAME), new NodeIdentifier(Topology.QNAME), NodeIdentifierWithPredicates.of(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), "test"), new NodeIdentifier(Node.QNAME), NodeIdentifierWithPredicates.of(Node.QNAME, QName.create(Node.QNAME, "node-id"), "test://test-node"));
    final DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
    final DOMEntityOwnershipCandidateRegistration reg = service1.registerCandidate(entity);
    await().untilAsserted(() -> {
        final RpcResult<GetEntityOutput> getEntityResult = service1.getEntity(new GetEntityInputBuilder().setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId))).setType(new EntityType(ENTITY_TYPE)).build()).get();
        assertEquals(getEntityResult.getResult().getOwnerNode().getValue(), "member-1");
        assertEquals(getEntityResult.getResult().getCandidateNodes().get(0).getValue(), "member-1");
    });
    // keep this under ask timeout to make sure the singleton actor in the inactive datacenter responds with failure
    // immediately, so that the rpc actor retries with distributed-data asap
    await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> {
        final GetEntitiesOutput getEntitiesResult = service2.getEntities(new GetEntitiesInputBuilder().build()).get().getResult();
        assertEquals(getEntitiesResult.getEntities().size(), 1);
        assertTrue(getEntitiesResult.getEntities().get(new EntitiesKey(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)), new EntityType(ENTITY_TYPE))).getCandidateNodes().contains(new NodeName("member-1")));
        assertTrue(getEntitiesResult.getEntities().get(new EntitiesKey(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)), new EntityType(ENTITY_TYPE))).getOwnerNode().getValue().equals("member-1"));
    });
    await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> {
        final GetEntityOutput getEntityResult = service2.getEntity(new GetEntityInputBuilder().setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId))).setType(new EntityType(ENTITY_TYPE)).build()).get().getResult();
        assertEquals(getEntityResult.getOwnerNode().getValue(), "member-1");
        assertEquals(getEntityResult.getCandidateNodes().get(0).getValue(), "member-1");
    });
    await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> {
        final GetEntityOwnerOutput getOwnerResult = service2.getEntityOwner(new GetEntityOwnerInputBuilder().setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId))).setType(new EntityType(ENTITY_TYPE)).build()).get().getResult();
        assertEquals(getOwnerResult.getOwnerNode().getValue(), "member-1");
    });
}
Also used : GetEntityOwnerInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerInputBuilder) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) EntityName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName) NodeName(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) EntitiesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.get.entities.output.EntitiesKey) GetEntityOwnerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerOutput) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) GetEntityInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityInputBuilder) EntityType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityType) GetEntityOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput) GetEntitiesInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesInputBuilder) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) GetEntitiesOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutput) Test(org.junit.Test)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)3 EntityName (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName)3 Test (org.junit.Test)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)2 DOMEntityOwnershipCandidateRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration)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 EntityType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityType)2 GetEntitiesInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesInputBuilder)2 GetEntitiesOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutput)2 GetEntityInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityInputBuilder)2 GetEntityOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput)2 GetEntityOwnerInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerInputBuilder)2 GetEntityOwnerOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerOutput)2 NodeName (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName)2 EntitiesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.get.entities.output.EntitiesKey)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1