Search in sources :

Example 81 with Service

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project openflowplugin by opendaylight.

the class AbstractService method handleServiceCall.

public ListenableFuture<RpcResult<O>> handleServiceCall(@Nonnull final I input, @Nullable final Function<OfHeader, Boolean> isComplete) {
    Preconditions.checkNotNull(input);
    final Class<?> requestType = input instanceof DataContainer ? DataContainer.class.cast(input).getImplementedInterface() : input.getClass();
    getMessageSpy().spyMessage(requestType, MessageSpy.StatisticsGroup.TO_SWITCH_ENTERED);
    LOG.trace("Handling general service call");
    final RequestContext<O> requestContext = requestContextStack.createRequestContext();
    if (Objects.isNull(requestContext)) {
        LOG.trace("Request context refused.");
        getMessageSpy().spyMessage(AbstractService.class, MessageSpy.StatisticsGroup.TO_SWITCH_DISREGARDED);
        return Futures.immediateFuture(RpcResultBuilder.<O>failed().withError(RpcError.ErrorType.APPLICATION, "", "Request quota exceeded").build());
    }
    if (Objects.isNull(requestContext.getXid())) {
        getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_RESERVATION_REJECTED);
        return RequestContextUtil.closeRequestContextWithRpcError(requestContext, "Outbound queue wasn't able to reserve XID.");
    }
    getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_READY_FOR_SUBMIT);
    final Xid xid = requestContext.getXid();
    OfHeader request = null;
    try {
        request = buildRequest(xid, input);
        Verify.verify(xid.getValue().equals(request.getXid()), "Expected XID %s got %s", xid.getValue(), request.getXid());
    } catch (ServiceException ex) {
        LOG.error("Failed to build request for {}, forfeiting request {}", input, xid.getValue(), ex);
        RequestContextUtil.closeRequestContextWithRpcError(requestContext, "failed to build request input: " + ex.getMessage());
    } finally {
        final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
        if (Objects.nonNull(isComplete)) {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType), isComplete);
        } else {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType));
        }
    }
    return requestContext.getFuture();
}
Also used : OutboundQueue(org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)

Example 82 with Service

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project openstack4j by ContainX.

the class KeystoneToken method getAggregatedCatalog.

/**
     * {@inheritDoc}
     */
@Override
@JsonIgnore
public SortedSetMultimap<String, Service> getAggregatedCatalog() {
    if (aggregatedCatalog == null) {
        synchronized (this) {
            if (aggregatedCatalog == null) {
                aggregatedCatalog = TreeMultimap.create();
                for (Service sc : catalog) {
                    String nameKey = TYPE_WITHOUT_VERSION.apply(sc.getName());
                    String typeKey = TYPE_WITHOUT_VERSION.apply(sc.getType());
                    aggregatedCatalog.put(nameKey, sc);
                    aggregatedCatalog.put(typeKey, sc);
                }
            }
        }
    }
    return aggregatedCatalog;
}
Also used : Service(org.openstack4j.model.identity.v3.Service) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 83 with Service

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project controller by opendaylight.

the class RoutedServiceIT method testServiceRegistration.

@Test
public void testServiceRegistration() {
    assertNotNull(broker);
    final BindingAwareProvider provider1 = new AbstractTestProvider() {

        @Override
        public void onSessionInitiated(final ProviderContext session) {
            assertNotNull(session);
            firstReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService1);
        }
    };
    LOG.info("Register provider 1 with first implementation of routeSimpleService - service1");
    broker.registerProvider(provider1);
    assertNotNull("Registration should not be null", firstReg);
    assertSame(odlRoutedService1, firstReg.getInstance());
    final BindingAwareProvider provider2 = new AbstractTestProvider() {

        @Override
        public void onSessionInitiated(final ProviderContext session) {
            assertNotNull(session);
            secondReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService2);
        }
    };
    LOG.info("Register provider 2 with second implementation of routeSimpleService - service2");
    broker.registerProvider(provider2);
    assertNotNull("Registration should not be null", firstReg);
    assertSame(odlRoutedService2, secondReg.getInstance());
    assertNotSame(secondReg, firstReg);
    final BindingAwareConsumer consumer = session -> consumerService = session.getRpcService(OpendaylightTestRoutedRpcService.class);
    LOG.info("Register routeService consumer");
    broker.registerConsumer(consumer);
    assertNotNull("MD-SAL instance of test Service should be returned", consumerService);
    assertNotSame("Provider instance and consumer instance should not be same.", odlRoutedService1, consumerService);
    final InstanceIdentifier<UnorderedList> nodeOnePath = createNodeRef("foo:node:1");
    LOG.info("Provider 1 registers path of node 1");
    firstReg.registerPath(TestContext.class, nodeOnePath);
    /**
     * Consumer creates addFlow message for node one and sends it to the
     * MD-SAL
     */
    final RoutedSimpleRouteInput simpleRouteFirstFoo = createSimpleRouteInput(nodeOnePath);
    consumerService.routedSimpleRoute(simpleRouteFirstFoo);
    /**
     * Verifies that implementation of the first provider received the same
     * message from MD-SAL.
     */
    verify(odlRoutedService1).routedSimpleRoute(simpleRouteFirstFoo);
    /**
     * Verifies that second instance was not invoked with first message
     */
    verify(odlRoutedService2, times(0)).routedSimpleRoute(simpleRouteFirstFoo);
    LOG.info("Provider 2 registers path of node 2");
    final InstanceIdentifier<UnorderedList> nodeTwo = createNodeRef("foo:node:2");
    secondReg.registerPath(TestContext.class, nodeTwo);
    /**
     * Consumer sends message to nodeTwo for three times. Should be
     * processed by second instance.
     */
    final RoutedSimpleRouteInput simpleRouteSecondFoo = createSimpleRouteInput(nodeTwo);
    consumerService.routedSimpleRoute(simpleRouteSecondFoo);
    consumerService.routedSimpleRoute(simpleRouteSecondFoo);
    consumerService.routedSimpleRoute(simpleRouteSecondFoo);
    /**
     * Verifies that second instance was invoked 3 times with second message
     * and first instance wasn't invoked.
     */
    verify(odlRoutedService2, times(3)).routedSimpleRoute(simpleRouteSecondFoo);
    verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteSecondFoo);
    LOG.info("Unregistration of the path for the node one in the first provider");
    firstReg.unregisterPath(TestContext.class, nodeOnePath);
    LOG.info("Provider 2 registers path of node 1");
    secondReg.registerPath(TestContext.class, nodeOnePath);
    /**
     * A consumer sends third message to node 1
     */
    final RoutedSimpleRouteInput simpleRouteThirdFoo = createSimpleRouteInput(nodeOnePath);
    consumerService.routedSimpleRoute(simpleRouteThirdFoo);
    /**
     * Verifies that provider 1 wasn't invoked and provider 2 was invoked 1
     * time.
     * TODO: fix unregister path
     */
    // verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteThirdFoo);
    verify(odlRoutedService2).routedSimpleRoute(simpleRouteThirdFoo);
}
Also used : OpendaylightTestRoutedRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService) UnorderedListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Assert.assertNotSame(org.junit.Assert.assertNotSame) LoggerFactory(org.slf4j.LoggerFactory) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) Lists(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists) Assert.assertSame(org.junit.Assert.assertSame) Before(org.junit.Before) UnorderedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) OpendaylightTestRoutedRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService) RoutedSimpleRouteInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder) RoutedRpcRegistration(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) UnorderedContainer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer) Mockito.verify(org.mockito.Mockito.verify) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Mockito(org.mockito.Mockito) Futures(com.google.common.util.concurrent.Futures) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TestContext(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.TestContext) RoutedSimpleRouteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput) Mockito.mock(org.mockito.Mockito.mock) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) UnorderedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList) RoutedSimpleRouteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Test(org.junit.Test)

Example 84 with Service

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testRemoveShardLeaderReplica.

@Test
public void testRemoveShardLeaderReplica() throws Exception {
    String name = "testRemoveShardLeaderReplica";
    String moduleShardsConfig = "module-shards-member1-and-2-and-3.conf";
    final MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).datastoreContextBuilder(DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(300).shardElectionTimeoutFactor(1)).build();
    final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    leaderNode1.configDataStore().waitTillReady();
    verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2", "member-3");
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1", "member-3");
    verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-1", "member-2");
    replicaNode2.waitForMembersUp("member-1", "member-3");
    replicaNode3.waitForMembersUp("member-1", "member-2");
    // Invoke RPC service on leader member-1 to remove it's local shard
    ClusterAdminRpcService service1 = new ClusterAdminRpcService(leaderNode1.configDataStore(), leaderNode1.operDataStore(), null);
    RpcResult<Void> rpcResult = service1.removeShardReplica(new RemoveShardReplicaInputBuilder().setShardName("cars").setMemberName("member-1").setDataStoreType(DataStoreType.Config).build()).get(10, TimeUnit.SECONDS);
    verifySuccessfulRpcResult(rpcResult);
    verifyRaftState(replicaNode2.configDataStore(), "cars", raftState -> assertThat("Leader Id", raftState.getLeader(), anyOf(containsString("member-2"), containsString("member-3"))));
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-3");
    verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-2");
    verifyNoShardPresent(leaderNode1.configDataStore(), "cars");
}
Also used : MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) RemoveShardReplicaInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveShardReplicaInputBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 85 with Service

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method getShardRole.

private RpcResult<GetShardRoleOutput> getShardRole(final MemberNode memberNode, final BindingNormalizedNodeSerializer serializer, final String shardName) throws Exception {
    final GetShardRoleInput input = new GetShardRoleInputBuilder().setDataStoreType(DataStoreType.Config).setShardName(shardName).build();
    final ClusterAdminRpcService service = new ClusterAdminRpcService(memberNode.configDataStore(), memberNode.operDataStore(), serializer);
    return service.getShardRole(input).get(10, TimeUnit.SECONDS);
}
Also used : GetShardRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleInputBuilder) GetShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleInput)

Aggregations

ArrayList (java.util.ArrayList)36 BigInteger (java.math.BigInteger)33 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)21 ExecutionException (java.util.concurrent.ExecutionException)19 CoreException (org.eclipse.core.runtime.CoreException)18 List (java.util.List)15 Test (org.junit.Test)15 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)15 Logger (org.slf4j.Logger)14 LoggerFactory (org.slf4j.LoggerFactory)14 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)13 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)12 BoundServices (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices)12 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)10 ServerPort (org.eclipse.wst.server.core.ServerPort)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)9 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)9