use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class ApplicationSerializer method fromSlime.
// ------------------ Deserialization
public Application fromSlime(Slime slime) {
Inspector root = slime.get();
ApplicationId id = ApplicationId.fromSerializedForm(root.field(idField).asString());
DeploymentSpec deploymentSpec = DeploymentSpec.fromXml(root.field(deploymentSpecField).asString(), false);
ValidationOverrides validationOverrides = ValidationOverrides.fromXml(root.field(validationOverridesField).asString());
List<Deployment> deployments = deploymentsFromSlime(root.field(deploymentsField));
DeploymentJobs deploymentJobs = deploymentJobsFromSlime(root.field(deploymentJobsField));
Change deploying = changeFromSlime(root.field(deployingField));
Change outstandingChange = changeFromSlime(root.field(outstandingChangeField));
Optional<IssueId> ownershipIssueId = optionalString(root.field(ownershipIssueIdField)).map(IssueId::from);
ApplicationMetrics metrics = new ApplicationMetrics(root.field(queryQualityField).asDouble(), root.field(writeQualityField).asDouble());
Optional<RotationId> rotation = rotationFromSlime(root.field(rotationField));
return new Application(id, deploymentSpec, validationOverrides, deployments, deploymentJobs, deploying, outstandingChange, ownershipIssueId, metrics, rotation);
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class ApplicationApiHandler method deploy.
private HttpResponse deploy(String tenantName, String applicationName, String instanceName, String environment, String region, HttpRequest request) {
ApplicationId applicationId = ApplicationId.from(tenantName, applicationName, instanceName);
ZoneId zone = ZoneId.from(environment, region);
Map<String, byte[]> dataParts = new MultipartParser().parse(request);
if (!dataParts.containsKey("deployOptions"))
return ErrorResponse.badRequest("Missing required form part 'deployOptions'");
Inspector deployOptions = SlimeUtils.jsonToSlime(dataParts.get("deployOptions")).get();
Optional<ApplicationPackage> applicationPackage = Optional.ofNullable(dataParts.get("applicationZip")).map(ApplicationPackage::new);
verifyApplicationIdentityConfiguration(tenantName, applicationPackage);
// TODO: get rid of the json object
DeployOptions deployOptionsJsonClass = new DeployOptions(screwdriverBuildJobFromSlime(deployOptions.field("screwdriverBuildJob")), optional("vespaVersion", deployOptions).map(Version::new), deployOptions.field("ignoreValidationErrors").asBool(), deployOptions.field("deployCurrentVersion").asBool());
ActivateResult result = controller.applications().deployApplication(applicationId, zone, applicationPackage, deployOptionsJsonClass);
return new SlimeJsonResponse(toSlime(result));
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class JobQueueSerializer method fromJson.
public Deque<ApplicationId> fromJson(byte[] data) {
Inspector inspector = SlimeUtils.jsonToSlime(data).get();
Deque<ApplicationId> queue = new ArrayDeque<>();
inspector.traverse((ArrayTraverser) (index, value) -> queue.addLast(ApplicationId.fromSerializedForm(value.asString())));
return queue;
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class StringSetSerializer method fromJson.
public Set<String> fromJson(byte[] data) {
Inspector inspector = SlimeUtils.jsonToSlime(data).get();
Set<String> stringSet = new HashSet<>();
inspector.traverse((ArrayTraverser) (index, name) -> stringSet.add(name.asString()));
return stringSet;
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class Maintainer method main.
public static void main(String[] args) {
LogSetup.initVespaLogging("node-maintainer");
if (args.length != 1) {
throw new RuntimeException("Expected only 1 argument - a JSON list of maintainer jobs to execute");
}
Inspector object = SlimeUtils.jsonToSlime(args[0].getBytes()).get();
if (object.type() != Type.ARRAY) {
throw new IllegalArgumentException("Expected a list of maintainer jobs to execute");
}
// Variable must be effectively final to be used in lambda expression
AtomicInteger numberOfJobsFailed = new AtomicInteger(0);
object.traverse((ArrayTraverser) (int i, Inspector item) -> {
try {
String type = getFieldOrFail(item, "type").asString();
Inspector arguments = getFieldOrFail(item, "arguments");
parseMaintenanceJob(type, arguments);
} catch (Exception e) {
System.err.println("Failed executing job: " + item.toString());
e.printStackTrace();
numberOfJobsFailed.incrementAndGet();
}
});
if (numberOfJobsFailed.get() > 0) {
System.err.println(numberOfJobsFailed.get() + " of jobs has failed");
System.exit(1);
}
}
Aggregations