use of com.yahoo.vespa.hosted.controller.api.ActivateResult 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.vespa.hosted.controller.api.ActivateResult in project vespa by vespa-engine.
the class ApplicationController method unexpectedDeployment.
private ActivateResult unexpectedDeployment(ApplicationId applicationId, ZoneId zone, Optional<ApplicationPackage> applicationPackage) {
Log logEntry = new Log();
logEntry.level = "WARNING";
logEntry.time = clock.instant().toEpochMilli();
logEntry.message = "Ignoring deployment of " + require(applicationId) + " to " + zone + " as a deployment is not currently expected";
PrepareResponse prepareResponse = new PrepareResponse();
prepareResponse.log = Collections.singletonList(logEntry);
prepareResponse.configChangeActions = new ConfigChangeActions(Collections.emptyList(), Collections.emptyList());
return new ActivateResult(new RevisionId(applicationPackage.map(ApplicationPackage::hash).orElse("0")), prepareResponse, applicationPackage.map(a -> a.zippedContent().length).orElse(0));
}
use of com.yahoo.vespa.hosted.controller.api.ActivateResult in project vespa by vespa-engine.
the class ApplicationController method deployApplication.
/**
* Deploys an application. If the application does not exist it is created.
*/
// TODO: Get rid of the options arg
public ActivateResult deployApplication(ApplicationId applicationId, ZoneId zone, Optional<ApplicationPackage> applicationPackageFromDeployer, DeployOptions options) {
try (Lock lock = lock(applicationId)) {
LockedApplication application = get(applicationId).map(app -> new LockedApplication(app, lock)).orElseGet(() -> new LockedApplication(createApplication(applicationId, Optional.empty()), lock));
final boolean canDeployDirectly = canDeployDirectlyTo(zone, options);
// Determine Vespa version to use
Version version;
if (options.deployCurrentVersion) {
version = application.versionIn(zone, controller);
} else if (canDeployDirectlyTo(zone, options)) {
version = options.vespaVersion.map(Version::new).orElse(controller.systemVersion());
} else if (!application.change().isPresent() && !zone.environment().isManuallyDeployed()) {
return unexpectedDeployment(applicationId, zone, applicationPackageFromDeployer);
} else {
version = application.deployVersionIn(zone, controller);
}
// Determine application package to use
Pair<ApplicationPackage, ApplicationVersion> artifact = artifactFor(zone, application, applicationPackageFromDeployer, canDeployDirectly, options.deployCurrentVersion);
ApplicationPackage applicationPackage = artifact.getFirst();
ApplicationVersion applicationVersion = artifact.getSecond();
validate(applicationPackage.deploymentSpec());
// Update application with information from application package
if (!options.deployCurrentVersion) {
// Store information about application package
application = application.with(applicationPackage.deploymentSpec());
application = application.with(applicationPackage.validationOverrides());
// Delete zones not listed in DeploymentSpec, if allowed
// We do this at deployment time to be able to return a validation failure message when necessary
application = deleteRemovedDeployments(application);
// Clean up deployment jobs that are no longer referenced by deployment spec
application = deleteUnreferencedDeploymentJobs(application);
// TODO jvenstad: Store triggering information here, including versions, when job status is read from the build service.
// store missing information even if we fail deployment below
store(application);
}
// Validate the change being deployed
if (!canDeployDirectly) {
validateChange(application, zone, version);
}
// Assign global rotation
application = withRotation(application, zone);
Set<String> rotationNames = new HashSet<>();
Set<String> cnames = new HashSet<>();
application.rotation().ifPresent(applicationRotation -> {
rotationNames.add(applicationRotation.id().asString());
cnames.add(applicationRotation.dnsName());
cnames.add(applicationRotation.secureDnsName());
});
// Carry out deployment
options = withVersion(version, options);
ConfigServerClient.PreparedApplication preparedApplication = configServer.prepare(new DeploymentId(applicationId, zone), options, cnames, rotationNames, applicationPackage.zippedContent());
preparedApplication.activate();
application = application.withNewDeployment(zone, applicationVersion, version, clock.instant());
store(application);
return new ActivateResult(new RevisionId(applicationPackage.hash()), preparedApplication.prepareResponse(), applicationPackage.zippedContent().length);
}
}
Aggregations