Search in sources :

Example 6 with Spec

use of com.yahoo.jrt.Spec in project vespa by vespa-engine.

the class FileDistributionStatus method getHostStatus.

HostStatus getHostStatus(String hostname, int port, Duration timeout) {
    Target target = supervisor.connect(new Spec(hostname, port));
    Request request = new Request("filedistribution.getActiveFileReferencesStatus");
    target.invokeSync(request, timeout.toMillis() / 1000);
    HostStatus hostStatus = createHostStatusFromResponse(hostname, request);
    target.close();
    return hostStatus;
}
Also used : Target(com.yahoo.jrt.Target) Request(com.yahoo.jrt.Request) Spec(com.yahoo.jrt.Spec)

Example 7 with Spec

use of com.yahoo.jrt.Spec in project vespa by vespa-engine.

the class RPCTargetPool method getTarget.

/**
 * This method will return a target for the given address. If a target does not currently exist for the given
 * address, it will be created and added to the internal map. Each target is also reference counted so that an
 * active target is never expired.
 *
 * @param orb     The supervisor to use to connect to the target.
 * @param address The address to resolve to a target.
 * @return A target for the given address.
 */
public RPCTarget getTarget(Supervisor orb, RPCServiceAddress address) {
    Spec spec = address.getConnectionSpec();
    String key = spec.toString();
    RPCTarget ret;
    synchronized (this) {
        Entry entry = targets.get(key);
        if (entry != null) {
            if (entry.target.getJRTTarget().isValid()) {
                entry.target.addRef();
                entry.lastUse = timer.milliTime();
                return entry.target;
            }
            entry.target.subRef();
            targets.remove(key);
        }
        ret = new RPCTarget(spec, orb);
        targets.put(key, new Entry(ret, timer.milliTime()));
    }
    ret.addRef();
    return ret;
}
Also used : Spec(com.yahoo.jrt.Spec)

Example 8 with Spec

use of com.yahoo.jrt.Spec in project vespa by vespa-engine.

the class MessageBusTestCase method testRoutingPolicyCache.

@Test
public void testRoutingPolicyCache() throws ListenFailedException, UnknownHostException {
    Slobrok slobrok = new Slobrok();
    String config = "slobrok[1]\nslobrok[0].connectionspec \"" + new Spec("localhost", slobrok.port()).toString() + "\"\n";
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory());
    MessageBus bus = new MessageBus(new RPCNetwork(new RPCNetworkParams().setSlobrokConfigId("raw:" + config)), new MessageBusParams().addProtocol(protocol));
    RoutingPolicy all = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", null);
    assertNotNull(all);
    RoutingPolicy ref = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", null);
    assertNotNull(ref);
    assertSame(all, ref);
    RoutingPolicy allArg = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", "Arg");
    assertNotNull(allArg);
    assertNotSame(all, allArg);
    RoutingPolicy refArg = bus.getRoutingPolicy(SimpleProtocol.NAME, "Custom", "Arg");
    assertNotNull(refArg);
    assertSame(allArg, refArg);
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) RPCNetworkParams(com.yahoo.messagebus.network.rpc.RPCNetworkParams) RPCNetwork(com.yahoo.messagebus.network.rpc.RPCNetwork) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) RoutingPolicy(com.yahoo.messagebus.routing.RoutingPolicy) Spec(com.yahoo.jrt.Spec) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory) Test(org.junit.Test)

Example 9 with Spec

use of com.yahoo.jrt.Spec in project vespa by vespa-engine.

the class FleetControllerTest method setWantedState.

protected void setWantedState(DummyVdsNode node, State state, String reason) {
    if (supervisor == null) {
        supervisor = new Supervisor(new Transport());
    }
    NodeState ns = new NodeState(node.getType(), state);
    if (reason != null)
        ns.setDescription(reason);
    Target connection = supervisor.connect(new Spec("localhost", fleetController.getRpcPort()));
    Request req = new Request("setNodeState");
    req.parameters().add(new StringValue(node.getSlobrokName()));
    req.parameters().add(new StringValue(ns.serialize()));
    connection.invokeSync(req, timeoutS);
    if (req.isError()) {
        assertTrue("Failed to invoke setNodeState(): " + req.errorCode() + ": " + req.errorMessage(), false);
    }
    if (!req.checkReturnTypes("s")) {
        assertTrue("Failed to invoke setNodeState(): Invalid return types.", false);
    }
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) Target(com.yahoo.jrt.Target) NodeState(com.yahoo.vdslib.state.NodeState) Request(com.yahoo.jrt.Request) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue)

Example 10 with Spec

use of com.yahoo.jrt.Spec in project vespa by vespa-engine.

the class DatabaseTest method setWantedState.

// Note: different semantics than FleetControllerTest.setWantedState
protected void setWantedState(Node n, NodeState ns, Map<Node, NodeState> wantedStates) {
    int rpcPort = fleetController.getRpcPort();
    if (supervisor == null) {
        supervisor = new Supervisor(new Transport());
    }
    Target connection = supervisor.connect(new Spec("localhost", rpcPort));
    assertTrue(connection.isValid());
    Request req = new Request("setNodeState");
    req.parameters().add(new StringValue("storage/cluster.mycluster/" + n.getType().toString() + "/" + n.getIndex()));
    req.parameters().add(new StringValue(ns.serialize(true)));
    connection.invokeSync(req, timeoutS);
    assertEquals(req.toString(), ErrorCode.NONE, req.errorCode());
    assertTrue(req.toString(), req.checkReturnTypes("s"));
    wantedStates.put(n, ns);
}
Also used : Supervisor(com.yahoo.jrt.Supervisor) Target(com.yahoo.jrt.Target) Request(com.yahoo.jrt.Request) Transport(com.yahoo.jrt.Transport) Spec(com.yahoo.jrt.Spec) StringValue(com.yahoo.jrt.StringValue)

Aggregations

Spec (com.yahoo.jrt.Spec)26 Request (com.yahoo.jrt.Request)14 Target (com.yahoo.jrt.Target)14 Supervisor (com.yahoo.jrt.Supervisor)13 Transport (com.yahoo.jrt.Transport)13 Test (org.junit.Test)9 StringValue (com.yahoo.jrt.StringValue)8 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)4 NodeState (com.yahoo.vdslib.state.NodeState)4 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)3 Distribution (com.yahoo.vdslib.distribution.Distribution)3 Node (com.yahoo.vdslib.state.Node)3 Register (com.yahoo.jrt.slobrok.api.Register)2 SlobrokList (com.yahoo.jrt.slobrok.api.SlobrokList)2 Identity (com.yahoo.messagebus.network.Identity)2 ClusterState (com.yahoo.vdslib.state.ClusterState)2 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 HostInfo (com.yahoo.config.model.api.HostInfo)1 PortInfo (com.yahoo.config.model.api.PortInfo)1