Search in sources :

Example 1 with ServiceJobSpec

use of com.netflix.titus.grpc.protogen.ServiceJobSpec in project titus-control-plane by Netflix.

the class JobTemplateCommand method createServiceJobDescriptor.

private JobDescriptor createServiceJobDescriptor() {
    Container container = createContainer().addAllEntryPoint(asList("sleep", "30")).build();
    ServiceJobSpec jobSpec = ServiceJobSpec.newBuilder().setCapacity(Capacity.newBuilder().setMin(1).setDesired(5).setMax(10).build()).setEnabled(true).setRetryPolicy(RetryPolicy.newBuilder().setDelayed(RetryPolicy.Delayed.newBuilder().setDelayMs(1000).setRetries(3))).build();
    return JobDescriptor.newBuilder().setApplicationName("myServiceApp").setOwner(createUser()).setCapacityGroup("service_workloads").setContainer(container).putAllAttributes(createLabels()).setJobGroupInfo(createJobGroupInfo()).setService(jobSpec).build();
}
Also used : Container(com.netflix.titus.grpc.protogen.Container) ServiceJobSpec(com.netflix.titus.grpc.protogen.ServiceJobSpec)

Example 2 with ServiceJobSpec

use of com.netflix.titus.grpc.protogen.ServiceJobSpec in project titus-control-plane by Netflix.

the class DefaultAppAutoScalingCallbackService method getScalableTargetResourceInfo.

@Override
public Observable<ScalableTargetResourceInfo> getScalableTargetResourceInfo(String jobId, CallMetadata callMetadata) {
    TaskQuery taskQuery = TaskQuery.newBuilder().putFilteringCriteria("jobIds", jobId).putFilteringCriteria("taskStates", "Started").setPage(Page.newBuilder().setPageSize(1).build()).build();
    return jobServiceGateway.findTasks(taskQuery, callMetadata).map(taskQueryResult -> taskQueryResult.getPagination().getTotalItems()).flatMap(numStartedTasks -> jobServiceGateway.findJob(jobId, callMetadata).map(job -> Pair.of(job, numStartedTasks))).flatMap(jobTasksPair -> {
        Job job = jobTasksPair.getLeft();
        Integer numRunningTasks = jobTasksPair.getRight();
        if (!job.getJobDescriptor().hasService()) {
            return Observable.error(JobManagerException.notServiceJob(jobId));
        }
        ServiceJobSpec jobSpec = job.getJobDescriptor().getService();
        ScalableTargetResourceInfo.Builder scalableTargetResourceInfoBuilder = ScalableTargetResourceInfo.newBuilder().actualCapacity(jobTasksPair.getRight()).desiredCapacity(jobSpec.getCapacity().getDesired()).dimensionName(DIMENSION_NAME).resourceName(jobId).scalableTargetDimensionId(jobId).version(buildVersion(job));
        if (jobSpec.getCapacity().getDesired() != numRunningTasks) {
            scalableTargetResourceInfoBuilder.scalingStatus(ScalingStatus.InProgress.name());
        } else {
            scalableTargetResourceInfoBuilder.scalingStatus(ScalingStatus.Successful.name());
        }
        return Observable.just(scalableTargetResourceInfoBuilder.build());
    });
}
Also used : Logger(org.slf4j.Logger) ServiceJobSpec(com.netflix.titus.grpc.protogen.ServiceJobSpec) UInt32Value(com.google.protobuf.UInt32Value) JobStatus(com.netflix.titus.grpc.protogen.JobStatus) LoggerFactory(org.slf4j.LoggerFactory) Job(com.netflix.titus.grpc.protogen.Job) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Page(com.netflix.titus.grpc.protogen.Page) Observable(rx.Observable) Inject(javax.inject.Inject) List(java.util.List) Pair(com.netflix.titus.common.util.tuple.Pair) Optional(java.util.Optional) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) JobServiceGateway(com.netflix.titus.runtime.jobmanager.gateway.JobServiceGateway) JobCapacityWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityWithOptionalAttributes) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobCapacityUpdateWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityUpdateWithOptionalAttributes) ServiceJobSpec(com.netflix.titus.grpc.protogen.ServiceJobSpec) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Job(com.netflix.titus.grpc.protogen.Job)

Aggregations

ServiceJobSpec (com.netflix.titus.grpc.protogen.ServiceJobSpec)2 UInt32Value (com.google.protobuf.UInt32Value)1 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)1 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)1 Pair (com.netflix.titus.common.util.tuple.Pair)1 Container (com.netflix.titus.grpc.protogen.Container)1 Job (com.netflix.titus.grpc.protogen.Job)1 JobCapacityUpdateWithOptionalAttributes (com.netflix.titus.grpc.protogen.JobCapacityUpdateWithOptionalAttributes)1 JobCapacityWithOptionalAttributes (com.netflix.titus.grpc.protogen.JobCapacityWithOptionalAttributes)1 JobStatus (com.netflix.titus.grpc.protogen.JobStatus)1 Page (com.netflix.titus.grpc.protogen.Page)1 TaskQuery (com.netflix.titus.grpc.protogen.TaskQuery)1 JobServiceGateway (com.netflix.titus.runtime.jobmanager.gateway.JobServiceGateway)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1