use of com.yahoo.component.Version in project vespa by vespa-engine.
the class SendAdapterTestCase method assertVersionedSend.
// //////////////////////////////////////////////////////////////////////////////
//
// Utilities
//
// //////////////////////////////////////////////////////////////////////////////
private void assertVersionedSend(Version srcVersion, Version itrVersion, Version dstVersion) {
System.out.println("Sending from " + srcVersion + " through " + itrVersion + " to " + dstVersion + ":");
srcServer.net.setVersion(srcVersion);
itrServer.net.setVersion(itrVersion);
dstServer.net.setVersion(dstVersion);
Message msg = new SimpleMessage("foo");
msg.getTrace().setLevel(9);
assertTrue(srcSession.send(msg, Route.parse("itr/session dst/session")).isAccepted());
assertNotNull(msg = ((Receptor) itrSession.getMessageHandler()).getMessage(300));
System.out.println("\tMessage version " + srcProtocol.lastVersion + " serialized at source.");
Version minVersion = srcVersion.compareTo(itrVersion) < 0 ? srcVersion : itrVersion;
assertEquals(minVersion, srcProtocol.lastVersion);
System.out.println("\tMessage version " + itrProtocol.lastVersion + " reached intermediate.");
assertEquals(minVersion, itrProtocol.lastVersion);
itrSession.forward(msg);
assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(300));
System.out.println("\tMessage version " + itrProtocol.lastVersion + " serialized at intermediate.");
minVersion = itrVersion.compareTo(dstVersion) < 0 ? itrVersion : dstVersion;
assertEquals(minVersion, itrProtocol.lastVersion);
System.out.println("\tMessage version " + dstProtocol.lastVersion + " reached destination.");
assertEquals(minVersion, dstProtocol.lastVersion);
Reply reply = new SimpleReply("bar");
reply.swapState(msg);
dstSession.reply(reply);
assertNotNull(reply = ((Receptor) itrSession.getReplyHandler()).getReply(300));
System.out.println("\tReply version " + dstProtocol.lastVersion + " serialized at destination.");
assertEquals(minVersion, dstProtocol.lastVersion);
System.out.println("\tReply version " + itrProtocol.lastVersion + " reached intermediate.");
assertEquals(minVersion, itrProtocol.lastVersion);
itrSession.forward(reply);
assertNotNull(((Receptor) srcSession.getReplyHandler()).getReply(300));
System.out.println("\tReply version " + itrProtocol.lastVersion + " serialized at intermediate.");
minVersion = srcVersion.compareTo(itrVersion) < 0 ? srcVersion : itrVersion;
assertEquals(minVersion, itrProtocol.lastVersion);
System.out.println("\tReply version " + srcProtocol.lastVersion + " reached source.");
assertEquals(minVersion, srcProtocol.lastVersion);
}
use of com.yahoo.component.Version in project vespa by vespa-engine.
the class RPCSendV2 method createReply.
@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
CompressionType compression = CompressionType.valueOf(ret.get(3).asInt8());
byte[] slimeBytes = compressor.decompress(ret.get(5).asData(), compression, ret.get(4).asInt32());
Slime slime = BinaryFormat.decode(slimeBytes);
Inspector root = slime.get();
Version version = new Version(root.field(VERSION_F).asString());
byte[] payload = root.field(BLOB_F).asData();
// Make sure that the owner understands the protocol.
Reply reply = null;
Error error = null;
if (payload.length > 0) {
Object retval = decode(new Utf8Array(root.field(PROTOCOL_F).asUtf8()), version, payload);
if (retval instanceof Reply) {
reply = (Reply) retval;
} else {
error = (Error) retval;
}
}
if (reply == null) {
reply = new EmptyReply();
}
if (error != null) {
reply.addError(error);
}
reply.setRetryDelay(root.field(RETRYDELAY_F).asDouble());
Inspector errors = root.field(ERRORS_F);
for (int i = 0; i < errors.entries(); i++) {
Inspector e = errors.entry(i);
String service = e.field(SERVICE_F).asString();
reply.addError(new Error((int) e.field(CODE_F).asLong(), e.field(MSG_F).asString(), (service != null && service.length() > 0) ? service : serviceName));
}
if (trace.getLevel() > 0) {
trace.getRoot().addChild(TraceNode.decode(root.field(TRACE_F).asString()));
}
return reply;
}
use of com.yahoo.component.Version in project vespa by vespa-engine.
the class RPCSendV2 method toParams.
protected Params toParams(Values args) {
CompressionType compression = CompressionType.valueOf(args.get(3).asInt8());
byte[] slimeBytes = compressor.decompress(args.get(5).asData(), compression, args.get(4).asInt32());
Slime slime = BinaryFormat.decode(slimeBytes);
Inspector root = slime.get();
Params p = new Params();
p.version = new Version(root.field(VERSION_F).asString());
p.route = root.field(ROUTE_F).asString();
p.session = root.field(SESSION_F).asString();
p.retryEnabled = root.field(USERETRY_F).asBool();
p.retry = (int) root.field(RETRY_F).asLong();
p.timeRemaining = root.field(TIMEREMAINING_F).asLong();
p.protocolName = new Utf8Array(Utf8.toBytes(root.field(PROTOCOL_F).asString()));
p.payload = root.field(BLOB_F).asData();
p.traceLevel = (int) root.field(TRACELEVEL_F).asLong();
return p;
}
use of com.yahoo.component.Version in project vespa by vespa-engine.
the class RPCTarget method handleRequestDone.
@Override
public void handleRequestDone(Request req) {
List<VersionHandler> handlers;
boolean shouldLog = log.isLoggable(LogLevel.DEBUG);
synchronized (this) {
targetInvoked = false;
if (req.checkReturnTypes("s")) {
String str = req.returnValues().get(0).asString();
try {
version = new Version(str);
if (shouldLog) {
log.log(LogLevel.DEBUG, "Target '" + name + "' has version " + version + ".");
}
} catch (IllegalArgumentException e) {
log.log(LogLevel.WARNING, "Failed to parse '" + str + "' as version for target '" + name + "'.", e);
}
} else {
log.log(LogLevel.INFO, "Method mbus.getVersion() failed for target '" + name + "'; " + req.errorMessage());
}
handlers = versionHandlers;
versionHandlers = new LinkedList<>();
}
for (VersionHandler handler : handlers) {
handler.handleVersion(version);
}
}
use of com.yahoo.component.Version in project vespa by vespa-engine.
the class ProvisioningTest method prepare.
private SystemState prepare(ApplicationId application, int container0Size, int container1Size, int content0Size, int content1Size, boolean required, String flavor, Version wantedVersion, ProvisioningTester tester) {
// "deploy prepare" with a two container clusters and a storage cluster having of two groups
ClusterSpec containerCluster0 = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("container0"), wantedVersion, false);
ClusterSpec containerCluster1 = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("container1"), wantedVersion, false);
ClusterSpec contentCluster0 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("content0"), wantedVersion, false);
ClusterSpec contentCluster1 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("content1"), wantedVersion, false);
Set<HostSpec> container0 = prepare(application, containerCluster0, container0Size, 1, required, flavor, tester);
Set<HostSpec> container1 = prepare(application, containerCluster1, container1Size, 1, required, flavor, tester);
Set<HostSpec> content0 = prepare(application, contentCluster0, content0Size, 1, required, flavor, tester);
Set<HostSpec> content1 = prepare(application, contentCluster1, content1Size, 1, required, flavor, tester);
Set<HostSpec> allHosts = new HashSet<>();
allHosts.addAll(container0);
allHosts.addAll(container1);
allHosts.addAll(content0);
allHosts.addAll(content1);
Function<Integer, Capacity> capacity = count -> Capacity.fromNodeCount(count, Optional.empty(), required);
int expectedContainer0Size = tester.capacityPolicies().decideSize(capacity.apply(container0Size));
int expectedContainer1Size = tester.capacityPolicies().decideSize(capacity.apply(container1Size));
int expectedContent0Size = tester.capacityPolicies().decideSize(capacity.apply(content0Size));
int expectedContent1Size = tester.capacityPolicies().decideSize(capacity.apply(content1Size));
assertEquals("Hosts in each group cluster is disjunct and the total number of unretired nodes is correct", expectedContainer0Size + expectedContainer1Size + expectedContent0Size + expectedContent1Size, tester.nonRetired(allHosts).size());
// Check cluster/group sizes
assertEquals(expectedContainer0Size, tester.nonRetired(container0).size());
assertEquals(expectedContainer1Size, tester.nonRetired(container1).size());
assertEquals(expectedContent0Size, tester.nonRetired(content0).size());
assertEquals(expectedContent1Size, tester.nonRetired(content1).size());
// Check cluster membership
tester.assertMembersOf(containerCluster0, container0);
tester.assertMembersOf(containerCluster1, container1);
tester.assertMembersOf(contentCluster0, content0);
tester.assertMembersOf(contentCluster1, content1);
return new SystemState(allHosts, container0, container1, content0, content1);
}
Aggregations