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();
}
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;
}
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);
}
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");
}
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);
}
Aggregations