index
int64
0
0
repo_id
stringlengths
26
205
file_path
stringlengths
51
246
content
stringlengths
8
433k
__index_level_0__
int64
0
10k
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/iam
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/iam/model/IamRole.java
/* * * * Copyright 2019 Netflix, Inc. * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * */ package com.netflix.titus.api.iam.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; /** * Describes an IAM Role Policy. */ public class IamRole { private final String roleId; private final String roleName; private final String resourceName; private final String assumePolicy; @JsonCreator public IamRole(@JsonProperty("roleId")String roleId, @JsonProperty("roleNmae")String roleName, @JsonProperty("arn")String resourceName, @JsonProperty("assumeRolePolicyDocument") String assumePolicy) { this.roleId = roleId; this.roleName = roleName; this.resourceName = resourceName; this.assumePolicy = assumePolicy; } public String getRoleId() { return roleId; } public String getRoleName() { return roleName; } public String getResourceName() { return resourceName; } public String getAssumePolicy() { return assumePolicy; } @Override public String toString() { return "IamRole{" + "roleId='" + roleId + '\'' + ", roleName='" + roleName + '\'' + ", resourceName='" + resourceName + '\'' + ", assumePolicy='" + assumePolicy + '\'' + '}'; } public static Builder newBuilder() { return new Builder(); } public static class Builder { private String roleId; private String roleName; private String resourceName; private String policyDoc; private Builder() {} public Builder withRoleId(String roleId) { this.roleId = roleId; return this; } public Builder withRoleName(String roleName) { this.roleName = roleName; return this; } public Builder withResourceName(String resourceName) { this.resourceName = resourceName; return this; } public Builder withPolicyDoc(String policyDoc) { this.policyDoc = policyDoc; return this; } public IamRole build() { return new IamRole(roleId, roleName, resourceName, policyDoc); } } }
9,600
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/iam
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/iam/service/IamConnectorException.java
/* * * * Copyright 2019 Netflix, Inc. * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * */ package com.netflix.titus.api.iam.service; import static java.lang.String.format; /** * A custom {@link RuntimeException} implementation that indicates errors communicating with a IAM connector. */ public class IamConnectorException extends RuntimeException { public enum ErrorCode { INTERNAL, IAM_NOT_FOUND, INVALID, } private final ErrorCode errorCode; private IamConnectorException(ErrorCode errorCode, String message) { this(errorCode, message, new RuntimeException(message)); } private IamConnectorException(ErrorCode errorCode, String message, Throwable cause) { super(message, cause); this.errorCode = errorCode; } public ErrorCode getErrorCode() { return errorCode; } public boolean isRetryable() { switch (errorCode) { case INTERNAL: return true; case IAM_NOT_FOUND: case INVALID: return false; } // Safe default return true; } public static IamConnectorException iamRoleNotFound(String iamRoleName) { return new IamConnectorException(ErrorCode.IAM_NOT_FOUND, format("Could not find IAM %s", iamRoleName)); } public static IamConnectorException iamRoleUnexpectedError(String iamRoleName) { return iamRoleUnexpectedError(iamRoleName, "Reason unknown"); } public static IamConnectorException iamRoleUnexpectedError(String iamRoleName, String message) { return new IamConnectorException(ErrorCode.INTERNAL, format("Unable to query IAM %s: %s", iamRoleName, message)); } public static IamConnectorException iamRoleCannotAssume(String iamRoleName, String iamAssumeRoleName) { return new IamConnectorException(ErrorCode.INVALID, format("Titus cannot assume into role %s: %s unable to assumeRole", iamRoleName, iamAssumeRoleName)); } }
9,601
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/json/ObjectMappers.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.json; import java.util.Collection; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.netflix.titus.api.appscale.model.AlarmConfiguration; import com.netflix.titus.api.appscale.model.AutoScalingPolicy; import com.netflix.titus.api.appscale.model.CustomizedMetricSpecification; import com.netflix.titus.api.appscale.model.MetricDimension; import com.netflix.titus.api.appscale.model.PolicyConfiguration; import com.netflix.titus.api.appscale.model.PredefinedMetricSpecification; import com.netflix.titus.api.appscale.model.StepAdjustment; import com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration; import com.netflix.titus.api.appscale.model.TargetTrackingPolicy; import com.netflix.titus.api.appscale.store.mixin.AlarmConfigurationMixIn; import com.netflix.titus.api.appscale.store.mixin.AutoScalingPolicyMixIn; import com.netflix.titus.api.appscale.store.mixin.CustomizedMetricSpecificationMixin; import com.netflix.titus.api.appscale.store.mixin.MetricDimensionMixin; import com.netflix.titus.api.appscale.store.mixin.PolicyConfigurationMixIn; import com.netflix.titus.api.appscale.store.mixin.PredefinedMetricSpecificationMixin; import com.netflix.titus.api.appscale.store.mixin.StepAdjustmentMixIn; import com.netflix.titus.api.appscale.store.mixin.StepScalingPolicyConfigurationMixIn; import com.netflix.titus.api.appscale.store.mixin.TargetTrackingPolicyMixin; import com.netflix.titus.api.jobmanager.model.job.BasicContainer; import com.netflix.titus.api.jobmanager.model.job.BatchJobTask; import com.netflix.titus.api.jobmanager.model.job.Capacity; import com.netflix.titus.api.jobmanager.model.job.Container; import com.netflix.titus.api.jobmanager.model.job.ContainerResources; import com.netflix.titus.api.jobmanager.model.job.Image; import com.netflix.titus.api.jobmanager.model.job.Job; import com.netflix.titus.api.jobmanager.model.job.JobDescriptor; import com.netflix.titus.api.jobmanager.model.job.JobGroupInfo; import com.netflix.titus.api.jobmanager.model.job.JobStatus; import com.netflix.titus.api.jobmanager.model.job.NetworkConfiguration; import com.netflix.titus.api.jobmanager.model.job.Owner; import com.netflix.titus.api.jobmanager.model.job.PlatformSidecar; import com.netflix.titus.api.jobmanager.model.job.SecurityProfile; import com.netflix.titus.api.jobmanager.model.job.ServiceJobProcesses; import com.netflix.titus.api.jobmanager.model.job.ServiceJobTask; import com.netflix.titus.api.jobmanager.model.job.Task; import com.netflix.titus.api.jobmanager.model.job.TaskStatus; import com.netflix.titus.api.jobmanager.model.job.TwoLevelResource; import com.netflix.titus.api.jobmanager.model.job.Version; import com.netflix.titus.api.jobmanager.model.job.VolumeMount; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.ContainerHealthProvider; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudgetPolicy; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudgetRate; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.HourlyTimeWindow; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.PercentagePerHourDisruptionBudgetRate; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePerIntervalDisruptionBudgetRate; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePercentagePerIntervalDisruptionBudgetRate; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RelocationLimitDisruptionBudgetPolicy; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.SelfManagedDisruptionBudgetPolicy; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.TimeWindow; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy; import com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnlimitedDisruptionBudgetRate; import com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume; import com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt; import com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt; import com.netflix.titus.api.jobmanager.model.job.migration.MigrationDetails; import com.netflix.titus.api.jobmanager.model.job.migration.MigrationPolicy; import com.netflix.titus.api.jobmanager.model.job.migration.SelfManagedMigrationPolicy; import com.netflix.titus.api.jobmanager.model.job.migration.SystemDefaultMigrationPolicy; import com.netflix.titus.api.jobmanager.model.job.retry.DelayedRetryPolicy; import com.netflix.titus.api.jobmanager.model.job.retry.ExponentialBackoffRetryPolicy; import com.netflix.titus.api.jobmanager.model.job.retry.ImmediateRetryPolicy; import com.netflix.titus.api.jobmanager.model.job.retry.RetryPolicy; import com.netflix.titus.api.jobmanager.model.job.volume.SaaSVolumeSource; import com.netflix.titus.api.jobmanager.model.job.volume.SharedContainerVolumeSource; import com.netflix.titus.api.jobmanager.model.job.volume.Volume; import com.netflix.titus.api.jobmanager.model.job.volume.VolumeSource; import com.netflix.titus.api.jobmanager.model.job.vpc.IpAddressAllocation; import com.netflix.titus.api.jobmanager.model.job.vpc.IpAddressLocation; import com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation; import com.netflix.titus.api.jobmanager.store.mixin.AvailabilityPercentageLimitDisruptionBudgetPolicyMixIn; import com.netflix.titus.api.jobmanager.store.mixin.BasicContainerMixin; import com.netflix.titus.api.jobmanager.store.mixin.BatchJobExtMixin; import com.netflix.titus.api.jobmanager.store.mixin.BatchJobTaskMixin; import com.netflix.titus.api.jobmanager.store.mixin.CapacityMixin; import com.netflix.titus.api.jobmanager.store.mixin.ContainerHealthProviderMixIn; import com.netflix.titus.api.jobmanager.store.mixin.ContainerMixin; import com.netflix.titus.api.jobmanager.store.mixin.ContainerResourcesMixin; import com.netflix.titus.api.jobmanager.store.mixin.DelayedRetryPolicyMixin; import com.netflix.titus.api.jobmanager.store.mixin.DisruptionBudgetMixIn; import com.netflix.titus.api.jobmanager.store.mixin.DisruptionBudgetPolicyMixIn; import com.netflix.titus.api.jobmanager.store.mixin.DisruptionBudgetRateMixIn; import com.netflix.titus.api.jobmanager.store.mixin.EbsVolumeMixIn; import com.netflix.titus.api.jobmanager.store.mixin.ExponentialBackoffRetryPolicyMixin; import com.netflix.titus.api.jobmanager.store.mixin.HourlyTimeWindowMixIn; import com.netflix.titus.api.jobmanager.store.mixin.ImageMixin; import com.netflix.titus.api.jobmanager.store.mixin.ImmediateRetryPolicyMixin; import com.netflix.titus.api.jobmanager.store.mixin.IpAddressAllocationMixin; import com.netflix.titus.api.jobmanager.store.mixin.IpAddressLocationMixin; import com.netflix.titus.api.jobmanager.store.mixin.JobDescriptorExtMixin; import com.netflix.titus.api.jobmanager.store.mixin.JobDescriptorMixin; import com.netflix.titus.api.jobmanager.store.mixin.JobGroupInfoMixin; import com.netflix.titus.api.jobmanager.store.mixin.JobMixin; import com.netflix.titus.api.jobmanager.store.mixin.JobStatusMixin; import com.netflix.titus.api.jobmanager.store.mixin.MigrationDetailsMixin; import com.netflix.titus.api.jobmanager.store.mixin.MigrationPolicyMixin; import com.netflix.titus.api.jobmanager.store.mixin.NetworkConfigurationMixin; import com.netflix.titus.api.jobmanager.store.mixin.OwnerMixin; import com.netflix.titus.api.jobmanager.store.mixin.PercentagePerHourDisruptionBudgetRateMixIn; import com.netflix.titus.api.jobmanager.store.mixin.PlatformSidecarMixin; import com.netflix.titus.api.jobmanager.store.mixin.RatePerIntervalDisruptionBudgetRateMixIn; import com.netflix.titus.api.jobmanager.store.mixin.RatePercentagePerIntervalDisruptionBudgetRateMixIn; import com.netflix.titus.api.jobmanager.store.mixin.RelocationLimitDisruptionBudgetPolicyMixIn; import com.netflix.titus.api.jobmanager.store.mixin.RetryPolicyMixin; import com.netflix.titus.api.jobmanager.store.mixin.SaaSVolumeSourceMixin; import com.netflix.titus.api.jobmanager.store.mixin.SecurityProfileMixin; import com.netflix.titus.api.jobmanager.store.mixin.SelfManagedDisruptionBudgetPolicyMixIn; import com.netflix.titus.api.jobmanager.store.mixin.SelfManagedMigrationPolicyMixin; import com.netflix.titus.api.jobmanager.store.mixin.ServiceJobExtMixin; import com.netflix.titus.api.jobmanager.store.mixin.ServiceJobProcessesMixin; import com.netflix.titus.api.jobmanager.store.mixin.ServiceJobTaskMixin; import com.netflix.titus.api.jobmanager.store.mixin.SharedContainerVolumeSourceMixin; import com.netflix.titus.api.jobmanager.store.mixin.SignedIpAddressAllocationMixin; import com.netflix.titus.api.jobmanager.store.mixin.SystemDefaultMigrationPolicyMixin; import com.netflix.titus.api.jobmanager.store.mixin.TaskInstancesMixin; import com.netflix.titus.api.jobmanager.store.mixin.TaskMixin; import com.netflix.titus.api.jobmanager.store.mixin.TaskStatusMixin; import com.netflix.titus.api.jobmanager.store.mixin.TimeWindowMixIn; import com.netflix.titus.api.jobmanager.store.mixin.TwoLevelResourceMixIn; import com.netflix.titus.api.jobmanager.store.mixin.UnhealthyTasksLimitDisruptionBudgetPolicyMixIn; import com.netflix.titus.api.jobmanager.store.mixin.UnlimitedDisruptionBudgetRateMixIn; import com.netflix.titus.api.jobmanager.store.mixin.VersionMixin; import com.netflix.titus.api.jobmanager.store.mixin.VolumeMixin; import com.netflix.titus.api.jobmanager.store.mixin.VolumeMountMixin; import com.netflix.titus.api.jobmanager.store.mixin.VolumeSourceMixin; import com.netflix.titus.api.model.ApplicationSLA; import com.netflix.titus.api.model.ResourceDimension; import com.netflix.titus.api.store.v2.ApplicationSlaMixIn; import com.netflix.titus.api.store.v2.ResourceDimensionMixin; import com.netflix.titus.common.util.jackson.CommonObjectMappers; /** * Jackson's {@link ObjectMapper} is thread safe, and uses cache for optimal performance. It makes sense * to reuse the same instance within single JVM. This class provides shared, pre-configured instances of * {@link ObjectMapper} with different configuration options. */ public class ObjectMappers { private static final ObjectMapper STORE = createStoreMapper(); private static final ObjectMapper APP_SCALE_STORE = createAppScalePolicyMapper(); public static ObjectMapper storeMapper() { return STORE; } public static ObjectMapper appScalePolicyMapper() { return APP_SCALE_STORE; } @Deprecated public static ObjectMapper jacksonDefaultMapper() { return CommonObjectMappers.jacksonDefaultMapper(); } @Deprecated public static ObjectMapper defaultMapper() { return CommonObjectMappers.defaultMapper(); } @Deprecated public static ObjectMapper compactMapper() { return CommonObjectMappers.compactMapper(); } @Deprecated public static ObjectMapper protobufMapper() { return CommonObjectMappers.protobufMapper(); } @Deprecated public static String writeValueAsString(ObjectMapper objectMapper, Object object) { return CommonObjectMappers.writeValueAsString(objectMapper, object); } @Deprecated public static <T> T readValue(ObjectMapper objectMapper, String json, Class<T> clazz) { return CommonObjectMappers.readValue(objectMapper, json, clazz); } @Deprecated public static ObjectMapper applyFieldsFilter(ObjectMapper original, Collection<String> fields) { return CommonObjectMappers.applyFieldsFilter(original, fields); } private static ObjectMapper createAppScalePolicyMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.registerModule(new Jdk8Module()); objectMapper.addMixIn(AlarmConfiguration.class, AlarmConfigurationMixIn.class); objectMapper.addMixIn(StepAdjustment.class, StepAdjustmentMixIn.class); objectMapper.addMixIn(StepScalingPolicyConfiguration.class, StepScalingPolicyConfigurationMixIn.class); objectMapper.addMixIn(PolicyConfiguration.class, PolicyConfigurationMixIn.class); objectMapper.addMixIn(AutoScalingPolicy.class, AutoScalingPolicyMixIn.class); objectMapper.addMixIn(TargetTrackingPolicy.class, TargetTrackingPolicyMixin.class); objectMapper.addMixIn(PredefinedMetricSpecification.class, PredefinedMetricSpecificationMixin.class); objectMapper.addMixIn(CustomizedMetricSpecification.class, CustomizedMetricSpecificationMixin.class); objectMapper.addMixIn(MetricDimension.class, MetricDimensionMixin.class); return objectMapper; } private static ObjectMapper createStoreMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.registerModule(new Jdk8Module()); // Common objectMapper.addMixIn(ResourceDimension.class, ResourceDimensionMixin.class); // Capacity management objectMapper.addMixIn(ApplicationSLA.class, ApplicationSlaMixIn.class); // Job Management objectMapper.addMixIn(Capacity.class, CapacityMixin.class); objectMapper.addMixIn(Job.class, JobMixin.class); objectMapper.addMixIn(JobDescriptor.class, JobDescriptorMixin.class); objectMapper.addMixIn(JobDescriptor.JobDescriptorExt.class, JobDescriptorExtMixin.class); objectMapper.addMixIn(JobStatus.class, JobStatusMixin.class); objectMapper.addMixIn(JobGroupInfo.class, JobGroupInfoMixin.class); objectMapper.addMixIn(Owner.class, OwnerMixin.class); objectMapper.addMixIn(Capacity.class, TaskInstancesMixin.class); objectMapper.addMixIn(RetryPolicy.class, RetryPolicyMixin.class); objectMapper.addMixIn(ImmediateRetryPolicy.class, ImmediateRetryPolicyMixin.class); objectMapper.addMixIn(DelayedRetryPolicy.class, DelayedRetryPolicyMixin.class); objectMapper.addMixIn(ExponentialBackoffRetryPolicy.class, ExponentialBackoffRetryPolicyMixin.class); objectMapper.addMixIn(MigrationPolicy.class, MigrationPolicyMixin.class); objectMapper.addMixIn(SystemDefaultMigrationPolicy.class, SystemDefaultMigrationPolicyMixin.class); objectMapper.addMixIn(SelfManagedMigrationPolicy.class, SelfManagedMigrationPolicyMixin.class); objectMapper.addMixIn(MigrationDetails.class, MigrationDetailsMixin.class); objectMapper.addMixIn(Task.class, TaskMixin.class); objectMapper.addMixIn(TwoLevelResource.class, TwoLevelResourceMixIn.class); objectMapper.addMixIn(BatchJobTask.class, BatchJobTaskMixin.class); objectMapper.addMixIn(ServiceJobTask.class, ServiceJobTaskMixin.class); objectMapper.addMixIn(BatchJobExt.class, BatchJobExtMixin.class); objectMapper.addMixIn(ServiceJobExt.class, ServiceJobExtMixin.class); objectMapper.addMixIn(TaskStatus.class, TaskStatusMixin.class); objectMapper.addMixIn(ContainerResources.class, ContainerResourcesMixin.class); objectMapper.addMixIn(SecurityProfile.class, SecurityProfileMixin.class); objectMapper.addMixIn(Container.class, ContainerMixin.class); objectMapper.addMixIn(BasicContainer.class, BasicContainerMixin.class); objectMapper.addMixIn(Image.class, ImageMixin.class); objectMapper.addMixIn(ServiceJobProcesses.class, ServiceJobProcessesMixin.class); objectMapper.addMixIn(NetworkConfiguration.class, NetworkConfigurationMixin.class); objectMapper.addMixIn(Version.class, VersionMixin.class); objectMapper.addMixIn(Volume.class, VolumeMixin.class); objectMapper.addMixIn(VolumeMount.class, VolumeMountMixin.class); objectMapper.addMixIn(VolumeSource.class, VolumeSourceMixin.class); objectMapper.addMixIn(SharedContainerVolumeSource.class, SharedContainerVolumeSourceMixin.class); objectMapper.addMixIn(SaaSVolumeSource.class, SaaSVolumeSourceMixin.class); objectMapper.addMixIn(PlatformSidecar.class, PlatformSidecarMixin.class); objectMapper.addMixIn(IpAddressLocation.class, IpAddressLocationMixin.class); objectMapper.addMixIn(IpAddressAllocation.class, IpAddressAllocationMixin.class); objectMapper.addMixIn(SignedIpAddressAllocation.class, SignedIpAddressAllocationMixin.class); objectMapper.addMixIn(EbsVolume.class, EbsVolumeMixIn.class); objectMapper.addMixIn(DisruptionBudget.class, DisruptionBudgetMixIn.class); objectMapper.addMixIn(DisruptionBudgetPolicy.class, DisruptionBudgetPolicyMixIn.class); objectMapper.addMixIn(AvailabilityPercentageLimitDisruptionBudgetPolicy.class, AvailabilityPercentageLimitDisruptionBudgetPolicyMixIn.class); objectMapper.addMixIn(SelfManagedDisruptionBudgetPolicy.class, SelfManagedDisruptionBudgetPolicyMixIn.class); objectMapper.addMixIn(UnhealthyTasksLimitDisruptionBudgetPolicy.class, UnhealthyTasksLimitDisruptionBudgetPolicyMixIn.class); objectMapper.addMixIn(RelocationLimitDisruptionBudgetPolicy.class, RelocationLimitDisruptionBudgetPolicyMixIn.class); objectMapper.addMixIn(DisruptionBudgetRate.class, DisruptionBudgetRateMixIn.class); objectMapper.addMixIn(PercentagePerHourDisruptionBudgetRate.class, PercentagePerHourDisruptionBudgetRateMixIn.class); objectMapper.addMixIn(RatePerIntervalDisruptionBudgetRate.class, RatePerIntervalDisruptionBudgetRateMixIn.class); objectMapper.addMixIn(RatePercentagePerIntervalDisruptionBudgetRate.class, RatePercentagePerIntervalDisruptionBudgetRateMixIn.class); objectMapper.addMixIn(UnlimitedDisruptionBudgetRate.class, UnlimitedDisruptionBudgetRateMixIn.class); objectMapper.addMixIn(ContainerHealthProvider.class, ContainerHealthProviderMixIn.class); objectMapper.addMixIn(TimeWindow.class, TimeWindowMixIn.class); objectMapper.addMixIn(HourlyTimeWindow.class, HourlyTimeWindowMixIn.class); return objectMapper; } }
9,602
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/audit
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/audit/model/AuditLogEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.audit.model; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; public class AuditLogEvent { public enum Type { // TODO remove these as we delete the v2 code NAMED_JOB_CREATE, NAMED_JOB_UPDATE, NAMED_JOB_DELETE, NAMED_JOB_DISABLED, NAMED_JOB_ENABLED, JOB_SUBMIT, JOB_TERMINATE, JOB_DELETE, JOB_SCALE_UP, JOB_SCALE_DOWN, JOB_SCALE_UPDATE, JOB_PROCESSES_UPDATE, JOB_IN_SERVICE_STATUS_CHANGE, WORKER_START, WORKER_TERMINATE, CLUSTER_SCALE_UP, CLUSTER_SCALE_DOWN, CLUSTER_ACTIVE_VMS // TODO implement the v3 auditing types } private final Type type; private final String operand; private final String data; private final long time; /** * As we keep only active state, job/task notifications when delivered to a handler may reference data removed * from memory. To avoid costly fetch from archive storage, we include them in the notification object itself. * This is a workaround for current V2 engine implementation, which we will fix in V3. */ @JsonIgnore private final Optional<Object> sourceRef; @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true) public AuditLogEvent( @JsonProperty("type") Type type, @JsonProperty("operand") String operand, @JsonProperty("data") String data, @JsonProperty("time") long time) { this.type = type; this.operand = operand; this.data = data; this.time = time; this.sourceRef = Optional.empty(); } public AuditLogEvent(Type type, String operand, String data, long time, Object sourceRef) { this.type = type; this.operand = operand; this.data = data; this.time = time; this.sourceRef = Optional.ofNullable(sourceRef); } public Type getType() { return type; } public String getOperand() { return operand; } public String getData() { return data; } public long getTime() { return time; } @JsonIgnore public Optional<Object> getSourceRef() { return sourceRef; } @Override public String toString() { return "AuditLogEvent{" + "type=" + type + ", operand='" + operand + '\'' + ", data='" + data + '\'' + ", time=" + time + ", sourceRef=" + sourceRef.map(r -> r.getClass().getSimpleName()).orElse("none") + '}'; } public static <SOURCE> AuditLogEvent of(Type type, String operand, String data, SOURCE sourceRef) { return new AuditLogEvent(type, operand, data, System.currentTimeMillis(), sourceRef); } }
9,603
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/audit
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/audit/service/AuditLogService.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.audit.service; import com.netflix.titus.api.audit.model.AuditLogEvent; import rx.Observable; /** * Audit logging API. */ public interface AuditLogService { /** * Submit new audit event. The event is added to an event queue, and it is guaranteed to immediately execute. */ void submit(AuditLogEvent event); /** * Returns a hot observable to the audit event stream. */ Observable<AuditLogEvent> auditLogEvents(); }
9,604
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model/TaskRelocationPlan.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.relocation.model; import java.util.Objects; import com.netflix.titus.common.util.Evaluators; public class TaskRelocationPlan { public enum TaskRelocationReason { AgentEvacuation, SelfManagedMigration, TaskMigration, Unknown, } private final String taskId; private final TaskRelocationReason reason; private final String reasonMessage; private final long decisionTime; private final long relocationTime; public TaskRelocationPlan(String taskId, TaskRelocationReason reason, String reasonMessage, long decisionTime, long relocationTime) { this.taskId = taskId; this.reason = Evaluators.getOrDefault(reason, TaskRelocationReason.Unknown); this.reasonMessage = reasonMessage; this.decisionTime = decisionTime; this.relocationTime = relocationTime; } public String getTaskId() { return taskId; } public TaskRelocationReason getReason() { return reason; } public String getReasonMessage() { return reasonMessage; } public long getDecisionTime() { return decisionTime; } public long getRelocationTime() { return relocationTime; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TaskRelocationPlan that = (TaskRelocationPlan) o; return decisionTime == that.decisionTime && relocationTime == that.relocationTime && Objects.equals(taskId, that.taskId) && reason == that.reason && Objects.equals(reasonMessage, that.reasonMessage); } @Override public int hashCode() { return Objects.hash(taskId, reason, reasonMessage, decisionTime, relocationTime); } @Override public String toString() { return "TaskRelocationPlan{" + "taskId='" + taskId + '\'' + ", reason=" + reason + ", reasonMessage='" + reasonMessage + '\'' + ", decisionTime=" + decisionTime + ", relocationTime=" + relocationTime + '}'; } public Builder toBuilder() { return newBuilder().withTaskId(taskId).withReason(reason).withReasonMessage(reasonMessage).withDecisionTime(decisionTime).withRelocationTime(relocationTime); } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private String taskId; private TaskRelocationReason reason; private String reasonMessage; private long decisionTime; private long relocationTime; private Builder() { } public Builder withTaskId(String taskId) { this.taskId = taskId; return this; } public Builder withReason(TaskRelocationReason reason) { this.reason = reason; return this; } public Builder withReasonMessage(String reasonMessage) { this.reasonMessage = reasonMessage; return this; } public Builder withDecisionTime(long decisionTime) { this.decisionTime = decisionTime; return this; } public Builder withRelocationTime(long relocationTime) { this.relocationTime = relocationTime; return this; } public TaskRelocationPlan build() { return new TaskRelocationPlan(taskId, reason, reasonMessage, decisionTime, relocationTime); } } }
9,605
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model/TaskRelocationStatus.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.relocation.model; import java.util.Objects; import com.google.common.base.Preconditions; public class TaskRelocationStatus { /** * Status code set when an operation completed successfully. */ public static final String STATUS_CODE_TERMINATED = "terminated"; /** * Status code set when a task eviction was rejected by the eviction service. */ public static final String STATUS_EVICTION_ERROR = "evictionError"; /** * Status code set when a task could not be terminated due to a system error (for example connectivity issue). */ public static final String STATUS_SYSTEM_ERROR = "systemError"; public enum TaskRelocationState { /// Reason codes: // * 'terminated' Success, /// Reason codes: // * 'noDisruptionBudget' Failure } private final String taskId; private final TaskRelocationState state; private final String statusCode; private final String statusMessage; private final TaskRelocationPlan taskRelocationPlan; private final long timestamp; public TaskRelocationStatus(String taskId, TaskRelocationState state, String statusCode, String statusMessage, TaskRelocationPlan taskRelocationPlan, long timestamp) { this.taskId = taskId; this.state = state; this.statusCode = statusCode; this.statusMessage = statusMessage; this.taskRelocationPlan = taskRelocationPlan; this.timestamp = timestamp; } public String getTaskId() { return taskId; } public TaskRelocationState getState() { return state; } public String getStatusCode() { return statusCode; } public String getStatusMessage() { return statusMessage; } public TaskRelocationPlan getTaskRelocationPlan() { return taskRelocationPlan; } public long getTimestamp() { return timestamp; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TaskRelocationStatus that = (TaskRelocationStatus) o; return timestamp == that.timestamp && Objects.equals(taskId, that.taskId) && state == that.state && Objects.equals(statusCode, that.statusCode) && Objects.equals(statusMessage, that.statusMessage) && Objects.equals(taskRelocationPlan, that.taskRelocationPlan); } @Override public int hashCode() { return Objects.hash(taskId, state, statusCode, statusMessage, taskRelocationPlan, timestamp); } @Override public String toString() { return "TaskRelocationStatus{" + "taskId='" + taskId + '\'' + ", state=" + state + ", statusCode='" + statusCode + '\'' + ", statusMessage='" + statusMessage + '\'' + ", taskRelocationPlan=" + taskRelocationPlan + ", timestamp=" + timestamp + '}'; } public Builder toBuilder() { return newBuilder().withTaskId(taskId).withState(state).withStatusCode(statusCode).withStatusMessage(statusMessage).withTaskRelocationPlan(taskRelocationPlan); } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private String taskId; private TaskRelocationState state; private String statusCode; private TaskRelocationPlan taskRelocationPlan; private String statusMessage; private long timestamp; private Builder() { } public Builder withTaskId(String taskId) { this.taskId = taskId; return this; } public Builder withState(TaskRelocationState state) { this.state = state; return this; } public Builder withStatusCode(String statusCode) { this.statusCode = statusCode; return this; } public Builder withStatusMessage(String statusMessage) { this.statusMessage = statusMessage; return this; } public Builder withTaskRelocationPlan(TaskRelocationPlan taskRelocationPlan) { this.taskRelocationPlan = taskRelocationPlan; return this; } public Builder withTimestamp(long timestamp) { this.timestamp = timestamp; return this; } public TaskRelocationStatus build() { Preconditions.checkNotNull(taskId, "Task id cannot be null"); Preconditions.checkNotNull(state, "Task state cannot be null"); Preconditions.checkNotNull(statusCode, "Status code cannot be null"); Preconditions.checkNotNull(statusMessage, "Status message cannot be null"); Preconditions.checkNotNull(taskRelocationPlan, "Task relocation plan cannot be null"); return new TaskRelocationStatus(taskId, state, statusCode, statusMessage, taskRelocationPlan, timestamp); } } }
9,606
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model/RelocationFunctions.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.relocation.model; import java.util.Objects; public final class RelocationFunctions { /** * Compares to plans, except the task relocation time. */ public static boolean areEqualExceptRelocationTime(TaskRelocationPlan first, TaskRelocationPlan second) { return Objects.equals(first.getTaskId(), second.getTaskId()) && Objects.equals(first.getReason(), second.getReason()) && Objects.equals(first.getReasonMessage(), second.getReasonMessage()); } }
9,607
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model/event/TaskRelocationPlanUpdateEvent.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.relocation.model.event; import java.util.Objects; import com.netflix.titus.api.relocation.model.TaskRelocationPlan; public class TaskRelocationPlanUpdateEvent extends TaskRelocationEvent { private final TaskRelocationPlan plan; public TaskRelocationPlanUpdateEvent(TaskRelocationPlan plan) { this.plan = plan; } public TaskRelocationPlan getPlan() { return plan; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TaskRelocationPlanUpdateEvent that = (TaskRelocationPlanUpdateEvent) o; return Objects.equals(plan, that.plan); } @Override public int hashCode() { return Objects.hash(plan); } @Override public String toString() { return "TaskRelocationPlanUpdateEvent{" + "plan=" + plan + '}'; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private TaskRelocationPlan plan; private Builder() { } public Builder withPlan(TaskRelocationPlan plan) { this.plan = plan; return this; } public Builder but() { return newBuilder().withPlan(plan); } public TaskRelocationPlanUpdateEvent build() { return new TaskRelocationPlanUpdateEvent(plan); } } }
9,608
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model/event/TaskRelocationPlanRemovedEvent.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.relocation.model.event; import java.util.Objects; public class TaskRelocationPlanRemovedEvent extends TaskRelocationEvent { private final String taskId; public TaskRelocationPlanRemovedEvent(String taskId) { this.taskId = taskId; } public String getTaskId() { return taskId; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TaskRelocationPlanRemovedEvent that = (TaskRelocationPlanRemovedEvent) o; return Objects.equals(taskId, that.taskId); } @Override public int hashCode() { return Objects.hash(taskId); } @Override public String toString() { return "TaskRelocationPlanRemovedEvent{" + "taskId='" + taskId + '\'' + '}'; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private String taskId; private Builder() { } public Builder withTaskId(String taskId) { this.taskId = taskId; return this; } public Builder but() { return newBuilder().withTaskId(taskId); } public TaskRelocationPlanRemovedEvent build() { return new TaskRelocationPlanRemovedEvent(taskId); } } }
9,609
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/model/event/TaskRelocationEvent.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.relocation.model.event; import com.netflix.titus.api.relocation.model.TaskRelocationPlan; public abstract class TaskRelocationEvent { public static TaskRelocationSnapshotEndEvent SNAPSHOT_END_EVENT = new TaskRelocationSnapshotEndEvent(); public static TaskRelocationKeepAliveEvent KEEP_ALIVE_EVENT = new TaskRelocationKeepAliveEvent(); public static TaskRelocationEvent newSnapshotEndEvent() { return SNAPSHOT_END_EVENT; } public static TaskRelocationEvent newKeepAliveEvent() { return KEEP_ALIVE_EVENT; } public static TaskRelocationPlanUpdateEvent taskRelocationPlanUpdated(TaskRelocationPlan plan) { return new TaskRelocationPlanUpdateEvent(plan); } public static TaskRelocationPlanRemovedEvent taskRelocationPlanRemoved(String taskId) { return new TaskRelocationPlanRemovedEvent(taskId); } private static class TaskRelocationSnapshotEndEvent extends TaskRelocationEvent { @Override public boolean equals(Object obj) { return obj instanceof TaskRelocationSnapshotEndEvent; } } private static class TaskRelocationKeepAliveEvent extends TaskRelocationEvent { @Override public boolean equals(Object obj) { return obj instanceof TaskRelocationKeepAliveEvent; } } }
9,610
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/relocation/service/ReadOnlyTaskRelocationService.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.relocation.service; import java.util.Map; import com.netflix.titus.api.relocation.model.TaskRelocationPlan; import com.netflix.titus.api.relocation.model.event.TaskRelocationEvent; import reactor.core.publisher.Flux; public interface ReadOnlyTaskRelocationService { /** * Returns all currently planned task relocations. Currently this will include only tasks needing relocation * with self managed disruption policy. */ Map<String, TaskRelocationPlan> getPlannedRelocations(); /** * Task relocation events. */ Flux<TaskRelocationEvent> events(); }
9,611
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest/representation/ReservationUsage.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.endpoint.v2.rest.representation; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class ReservationUsage { private static final ReservationUsage NONE = new ReservationUsage(0, 0, 0, 0); private final double cpu; private final long memoryMB; private final long diskMB; private final long networkMbs; @JsonCreator public ReservationUsage(@JsonProperty("cpu") double cpu, @JsonProperty("memoryMB") long memoryMB, @JsonProperty("diskMB") long diskMB, @JsonProperty("networkMbs") long networkMbs) { this.cpu = cpu; this.memoryMB = memoryMB; this.diskMB = diskMB; this.networkMbs = networkMbs; } public static ReservationUsage none() { return NONE; } public double getCpu() { return cpu; } public long getMemoryMB() { return memoryMB; } public long getDiskMB() { return diskMB; } public long getNetworkMbs() { return networkMbs; } }
9,612
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest/representation/LeaderRepresentation.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.endpoint.v2.rest.representation; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class LeaderRepresentation { private final String hostname; private final String hostIP; private final int apiPort; private final String apiStatusUri; private final long createTime; @JsonCreator public LeaderRepresentation(@JsonProperty("hostname") String hostname, @JsonProperty("hostIP") String hostIP, @JsonProperty("apiPort") int apiPort, @JsonProperty("apiStatusUri") String apiStatusUri, @JsonProperty("createTime") long createTime) { this.hostname = hostname; this.hostIP = hostIP; this.apiPort = apiPort; this.apiStatusUri = apiStatusUri; this.createTime = createTime; } public String getHostname() { return hostname; } public String getHostIP() { return hostIP; } public int getApiPort() { return apiPort; } public String getApiStatusUri() { return apiStatusUri; } public long getCreateTime() { return createTime; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private String hostname; private String hostIP; private int apiPort; private String apiStatusUri; private long createTime; private Builder() { } public Builder withHostname(String hostname) { this.hostname = hostname; return this; } public Builder withHostIP(String hostIP) { this.hostIP = hostIP; return this; } public Builder withApiPort(int apiPort) { this.apiPort = apiPort; return this; } public Builder withApiStatusUri(String apiStatusUri) { this.apiStatusUri = apiStatusUri; return this; } public Builder withCreateTime(long createTime) { this.createTime = createTime; return this; } public LeaderRepresentation build() { return new LeaderRepresentation(hostname, hostIP, apiPort, apiStatusUri, createTime); } } }
9,613
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest/representation/TitusTaskState.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.endpoint.v2.rest.representation; /** */ public enum TitusTaskState { QUEUED, DISPATCHED, STARTING, RUNNING, FINISHED, ERROR, STOPPED, CRASHED, FAILED; }
9,614
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest/representation/ApplicationSlaRepresentation.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.endpoint.v2.rest.representation; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; /** * Application SLA model for v2 REST API. Each job type (service, batch) can be scheduled in any tier. * <p> * <h1>Capacity guarantee</h1> * An application has to define resources required by their tasks. It is expected (but not verified yet), that * all application's jobs will include the resource allocations identical to those requested in SLA. * Together with resource dimensions, the application SLA defines a total number of instances it expects to * require for peek allocation. This is not a constraint, and the application can ask for more resources, but * these may not be readily available, and may require scale up action. If scale-up is not possible, as maximum * size of the agent server group is reached, application's excessive tasks will be queued. * <p> * <h1>Fitness</h1> * Agent cluster allocation is based on job fitness criteria (how well its resources match a given instance type). * As service job is expected always to run on an instance available within its tier, it may be a mismatch between fitness * calculated best-agent, and the SLA-level restriction. To resolve this, a global constraint is provided that * restricts the application to run on instance types from within its tier. * <p> * <h1>Agent cluster assignment</h1> * It is expected that only one agent server group per instance type exists. This can be not true however under * certain circumstances, like Titus agent redeployment. If there are multiple clusters deployed with the same * instance type, the sum of their resources is checked against expected SLA resource level. If not sufficient * resources are present, any of those clusters (one or many) may be chosen for scale-up action * (setting new min-ASG level). */ public class ApplicationSlaRepresentation { @NotNull(message = "'appName' is a required property") private final String appName; /** * If service tier is not defined it is defaulted to {@link TierRepresentation#Flex}. */ private final TierRepresentation tier; @NotNull(message = "'instanceCPU' is a required property") @Min(value = 1, message = "'instanceCPU' must be at least 1") private final Double instanceCPU; @NotNull(message = "'instanceMemoryMB' is a required property") @Min(value = 1, message = "'instanceMemoryMB' must be at least 1MB") private final Long instanceMemoryMB; @NotNull(message = "'instanceDiskMB' is a required property") @Min(value = 1, message = "'instanceDiskMB' must be at least 1MB") private final Long instanceDiskMB; @NotNull(message = "'instanceNetworkMbs' is a required property") @Min(value = 1, message = "'instanceNetworkMbs' must be at least 1Mbs") private final Long instanceNetworkMbs; /** * Total number of instances required by this application. Titus will keep pre-allocated resources to always * fulfill this requirement. */ @NotNull(message = "'instanceCount' is a required property") @Min(value = 1, message = "'instanceCount' must be at least 1") private final Integer instanceCount; @Min(value = 0, message = "'instanceGPU' must be at least 0") private final Long instanceGPU; // ---------------------------------------------------------------- // Fields of the extended model. private final String cellId; private final ReservationUsage reservationUsage; /** * If the managing scheduler is not specified, default scheduler is used. */ private final String schedulerName; /** * Defines the resourcePool to use for managing capacity for applications using this SLA definition. */ private final String resourcePool; @JsonCreator public ApplicationSlaRepresentation(@JsonProperty("appName") String appName, @JsonProperty("cellId") String cellId, @JsonProperty("tier") TierRepresentation tier, @JsonProperty("instanceCPU") Double instanceCPU, @JsonProperty("instanceMemoryMB") Long instanceMemoryMB, @JsonProperty("instanceDiskMB") Long instanceDiskMB, @JsonProperty("instanceNetworkMbs") Long instanceNetworkMbs, @JsonProperty(value = "instanceGPU", defaultValue = "0") Long instanceGPU, @JsonProperty("instanceCount") Integer instanceCount, @JsonProperty("reservationUsage") ReservationUsage reservationUsage, @JsonProperty(value = "schedulerName", defaultValue = "fenzo") String schedulerName, @JsonProperty("resourcePool") String resourcePool) { this.appName = appName; this.cellId = cellId; this.tier = tier; this.instanceCPU = instanceCPU; this.instanceMemoryMB = instanceMemoryMB; this.instanceDiskMB = instanceDiskMB; this.instanceNetworkMbs = instanceNetworkMbs; if (instanceGPU == null) { this.instanceGPU = 0L; } else { this.instanceGPU = instanceGPU; } this.instanceCount = instanceCount; this.reservationUsage = reservationUsage; this.schedulerName = schedulerName; this.resourcePool = resourcePool; } public String getAppName() { return appName; } public String getCellId() { return cellId; } public TierRepresentation getTier() { return tier; } public Double getInstanceCPU() { return instanceCPU; } public Long getInstanceMemoryMB() { return instanceMemoryMB; } public Long getInstanceDiskMB() { return instanceDiskMB; } public Long getInstanceNetworkMbs() { return instanceNetworkMbs; } public Long getInstanceGPU() { return instanceGPU; } public Integer getInstanceCount() { return instanceCount; } public ReservationUsage getReservationUsage() { return reservationUsage; } public String getResourcePool() { return resourcePool; } public String getSchedulerName() { return schedulerName; } }
9,615
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest/representation/TierRepresentation.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.endpoint.v2.rest.representation; public enum TierRepresentation { Critical, Flex }
9,616
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest/representation/TitusJobType.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.endpoint.v2.rest.representation; public enum TitusJobType {batch, service}
9,617
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/endpoint/v2/rest/representation/ServerStatusRepresentation.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.endpoint.v2.rest.representation; import java.util.List; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class ServerStatusRepresentation { private final boolean leader; private final boolean active; private final String uptime; private final String electionTimeStamp; private final String activeTimeStamp; private final String activationTime; private final List<ServiceActivation> serviceActivationTimes; private final List<String> serviceActivationOrder; @JsonCreator public ServerStatusRepresentation( @JsonProperty("leader") boolean leader, @JsonProperty("active") boolean active, @JsonProperty("upTime") String uptime, @JsonProperty("electionTimeStamp") String electionTimeStamp, @JsonProperty("activeTimeStamp") String activeTimeStamp, @JsonProperty("activationTime") String activationTime, @JsonProperty("serviceActivationTimes") List<ServiceActivation> serviceActivationTimes, @JsonProperty("serviceActivationOrder") List<String> serviceActivationOrder) { this.leader = leader; this.active = active; this.uptime = uptime; this.electionTimeStamp = electionTimeStamp; this.activeTimeStamp = activeTimeStamp; this.activationTime = activationTime; this.serviceActivationTimes = serviceActivationTimes; this.serviceActivationOrder = serviceActivationOrder; } public boolean isLeader() { return leader; } public boolean isActive() { return active; } public String getUptime() { return uptime; } public String getElectionTimeStamp() { return electionTimeStamp; } public String getActiveTimeStamp() { return activeTimeStamp; } public String getActivationTime() { return activationTime; } public List<ServiceActivation> getServiceActivationTimes() { return serviceActivationTimes; } public List<String> getServiceActivationOrder() { return serviceActivationOrder; } public static class ServiceActivation { private final String service; private final String duration; @JsonCreator public ServiceActivation( @JsonProperty("service") String service, @JsonProperty("duration") String duration) { this.service = service; this.duration = duration; } public String getService() { return service; } public String getDuration() { return duration; } } }
9,618
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/federation
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/federation/model/RemoteFederation.java
package com.netflix.titus.api.federation.model; public final class RemoteFederation { private final String address; public RemoteFederation(String address) { this.address = address; } public String getAddress() { return address; } }
9,619
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/federation
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/federation/model/Cell.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.federation.model; import java.util.Objects; public final class Cell implements Comparable<Cell> { private final String name; private final String address; public Cell(String name, String address) { this.name = name; this.address = address; } public String getName() { return name; } public String getAddress() { return address; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Cell)) { return false; } Cell cell = (Cell) o; return Objects.equals(name, cell.name) && Objects.equals(address, cell.address); } @Override public int hashCode() { return Objects.hash(name, address); } @Override public String toString() { return "Cell{" + "name='" + name + '\'' + ", address='" + address + '\'' + '}'; } @Override public int compareTo(Cell cell) { return name.compareTo(cell.getName()); } }
9,620
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/TokenBucketPolicies.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import java.util.concurrent.TimeUnit; import com.google.common.base.Preconditions; import com.netflix.titus.common.util.limiter.Limiters; import com.netflix.titus.common.util.limiter.tokenbucket.TokenBucket; import com.netflix.titus.common.util.time.Clocks; /** * Supplementary functions to work with the token bucket policies. */ public final class TokenBucketPolicies { private TokenBucketPolicies() { } /** * Create a new token bucket instance from the provided policy. */ public static TokenBucket newTokenBucket(String name, TokenBucketPolicy policy) { Preconditions.checkArgument( policy.getRefillPolicy() instanceof FixedIntervalTokenBucketRefillPolicy, "Only FixedIntervalTokenBucketRefillPolicy supported" ); FixedIntervalTokenBucketRefillPolicy refillPolicy = (FixedIntervalTokenBucketRefillPolicy) policy.getRefillPolicy(); return Limiters.createFixedIntervalTokenBucket( name, policy.getCapacity(), policy.getInitialNumberOfTokens(), refillPolicy.getNumberOfTokensPerInterval(), refillPolicy.getIntervalMs(), TimeUnit.MILLISECONDS, Clocks.system() ); } }
9,621
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/ResourceDimension.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import java.util.Objects; import javax.validation.constraints.Min; /** * Encapsulates information application or server resources (CPU, memory, disk, etc). */ // TODO: this model is also used to represent resource asks (reservations) and utilization, which have different // requirements (e.g.: not everything that is being utilized was reserved) public class ResourceDimension { @Min(value = 0, message = "'cpu' must be >= 0, but is #{#root}") private final double cpu; @Min(value = 0, message = "'gpus' must be >= 0, but is #{#root}") private final long gpu; @Min(value = 0, message = "'memoryMB' must be >= 0, but is #{#root}") private final long memoryMB; @Min(value = 0, message = "'diskMB' must be >= 0, but is #{#root}") private final long diskMB; @Min(value = 0, message = "'networkMbs' must be >= 0, but is #{#root}") private final long networkMbs; @Min(value = 0, message = "'opportunisticCpu' must be >= 0, but is #{#root}") private final long opportunisticCpu; public ResourceDimension(double cpu, long gpu, long memoryMB, long diskMB, long networkMbs, long opportunisticCpu) { this.cpu = cpu; this.gpu = gpu; this.memoryMB = memoryMB; this.diskMB = diskMB; this.networkMbs = networkMbs; this.opportunisticCpu = opportunisticCpu; } public double getCpu() { return cpu; } public long getGpu() { return gpu; } public long getMemoryMB() { return memoryMB; } public long getDiskMB() { return diskMB; } public long getNetworkMbs() { return networkMbs; } public long getOpportunisticCpu() { return opportunisticCpu; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ResourceDimension that = (ResourceDimension) o; return Double.compare(that.cpu, cpu) == 0 && gpu == that.gpu && memoryMB == that.memoryMB && diskMB == that.diskMB && networkMbs == that.networkMbs && opportunisticCpu == that.opportunisticCpu; } @Override public int hashCode() { return Objects.hash(cpu, gpu, memoryMB, diskMB, networkMbs, opportunisticCpu); } @Override public String toString() { return "ResourceDimension{" + "cpu=" + cpu + ", gpu=" + gpu + ", memoryMB=" + memoryMB + ", diskMB=" + diskMB + ", networkMbs=" + networkMbs + ", opportunisticCpu=" + opportunisticCpu + '}'; } public Builder toBuilder() { return newBuilder(this); } public static ResourceDimension empty() { return new ResourceDimension(0, 0, 0, 0, 0, 0); } public static Builder newBuilder() { return new Builder(); } public static Builder newBuilder(ResourceDimension source) { return new Builder() .withCpus(source.getCpu()) .withGpu(source.getGpu()) .withMemoryMB(source.getMemoryMB()) .withDiskMB(source.getDiskMB()) .withNetworkMbs(source.getNetworkMbs()) .withOpportunisticCpus(source.getOpportunisticCpu()); } public static final class Builder { private double cpus; private long gpu; private long memoryMB; private long diskMB; private long networkMbs; private long opportunisticCpus; private Builder() { } public Builder withCpus(double cpus) { this.cpus = cpus; return this; } public Builder withGpu(long gpu) { this.gpu = gpu; return this; } public Builder withMemoryMB(long memoryMB) { this.memoryMB = memoryMB; return this; } public Builder withDiskMB(long diskMB) { this.diskMB = diskMB; return this; } public Builder withNetworkMbs(long networkMbs) { this.networkMbs = networkMbs; return this; } public Builder withOpportunisticCpus(long cpus) { this.opportunisticCpus = cpus; return this; } public Builder but() { return newBuilder().withCpus(cpus).withGpu(gpu).withMemoryMB(memoryMB).withDiskMB(diskMB).withNetworkMbs(networkMbs) .withOpportunisticCpus(opportunisticCpus); } public ResourceDimension build() { return new ResourceDimension(cpus, gpu, memoryMB, diskMB, networkMbs, opportunisticCpus); } } }
9,622
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/TokenBucketRefillPolicy.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; public abstract class TokenBucketRefillPolicy { }
9,623
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/SelfManagedMigrationPolicy.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import com.fasterxml.jackson.annotation.JsonCreator; public class SelfManagedMigrationPolicy extends MigrationPolicy { @JsonCreator public SelfManagedMigrationPolicy() { } }
9,624
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/SchedulerConstants.java
/* * Copyright 2021 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; /** * Miscellaneous constants for supported Schedulers. */ public final class SchedulerConstants { private SchedulerConstants() { } /** * This constant is used to classify any {@link ApplicationSLA} instances associated with Fenzo scheduler. */ public static final String SCHEDULER_NAME_FENZO = "fenzo"; /** * This constant is used to identify any {@link ApplicationSLA} instances associated with Kube Scheduler. */ public static final String SCHEDULER_NAME_KUBE_SCHEDULER = "kubeScheduler"; }
9,625
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/Tier.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; public enum Tier { Critical, Flex }
9,626
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/FixedIntervalTokenBucketRefillPolicy.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import java.util.Objects; public class FixedIntervalTokenBucketRefillPolicy extends TokenBucketRefillPolicy { private final long numberOfTokensPerInterval; private final long intervalMs; public FixedIntervalTokenBucketRefillPolicy(long numberOfTokensPerInterval, long intervalMs) { this.numberOfTokensPerInterval = numberOfTokensPerInterval; this.intervalMs = intervalMs; } public long getNumberOfTokensPerInterval() { return numberOfTokensPerInterval; } public long getIntervalMs() { return intervalMs; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FixedIntervalTokenBucketRefillPolicy that = (FixedIntervalTokenBucketRefillPolicy) o; return numberOfTokensPerInterval == that.numberOfTokensPerInterval && intervalMs == that.intervalMs; } @Override public int hashCode() { return Objects.hash(numberOfTokensPerInterval, intervalMs); } @Override public String toString() { return "FixedIntervalTokenBucketRefillPolicy{" + "numberOfTokensPerInterval=" + numberOfTokensPerInterval + ", intervalMs=" + intervalMs + "}"; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private long numberOfTokensPerInterval; private long intervalMs; private Builder() { } public Builder withNumberOfTokensPerInterval(long numberOfTokensPerInterval) { this.numberOfTokensPerInterval = numberOfTokensPerInterval; return this; } public Builder withIntervalMs(long intervalMs) { this.intervalMs = intervalMs; return this; } public FixedIntervalTokenBucketRefillPolicy build() { return new FixedIntervalTokenBucketRefillPolicy(numberOfTokensPerInterval, intervalMs); } } }
9,627
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/Level.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; public enum Level { System, Tier, CapacityGroup, Job, Task }
9,628
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/EfsMount.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; /** * EFS mount information */ public class EfsMount { public enum MountPerm {RO, WO, RW} @NotNull(message = "'efsId' is null") @Size(min = 1, message = "Empty value not allowed") private final String efsId; @NotNull(message = "'mountPoint' is null") @Size(min = 1, message = "Empty value not allowed") private final String mountPoint; @NotNull(message = "'mountPerm' is null") private final EfsMount.MountPerm mountPerm; private final String efsRelativeMountPoint; @JsonCreator public EfsMount(@JsonProperty("efsId") String efsId, @JsonProperty("mountPoint") String mountPoint, @JsonProperty("mountPerm") EfsMount.MountPerm mountPerm, @JsonProperty("efsRelativeMountPoint") String efsRelativeMountPoint) { this.efsId = efsId; this.mountPoint = mountPoint; this.mountPerm = mountPerm; this.efsRelativeMountPoint = efsRelativeMountPoint; } public static EfsMount.Builder newBuilder(EfsMount efsMount) { return newBuilder() .withEfsId(efsMount.getEfsId()) .withMountPoint(efsMount.getMountPoint()) .withMountPerm(efsMount.getMountPerm()) .withEfsRelativeMountPoint(efsMount.getEfsRelativeMountPoint()); } public static EfsMount.Builder newBuilder() { return new EfsMount.Builder(); } public String getEfsId() { return efsId; } public String getMountPoint() { return mountPoint; } public EfsMount.MountPerm getMountPerm() { return mountPerm; } public String getEfsRelativeMountPoint() { return efsRelativeMountPoint; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } EfsMount efsMount = (EfsMount) o; if (efsId != null ? !efsId.equals(efsMount.efsId) : efsMount.efsId != null) { return false; } if (mountPoint != null ? !mountPoint.equals(efsMount.mountPoint) : efsMount.mountPoint != null) { return false; } if (mountPerm != efsMount.mountPerm) { return false; } return efsRelativeMountPoint != null ? efsRelativeMountPoint.equals(efsMount.efsRelativeMountPoint) : efsMount.efsRelativeMountPoint == null; } @Override public int hashCode() { int result = efsId != null ? efsId.hashCode() : 0; result = 31 * result + (mountPoint != null ? mountPoint.hashCode() : 0); result = 31 * result + (mountPerm != null ? mountPerm.hashCode() : 0); result = 31 * result + (efsRelativeMountPoint != null ? efsRelativeMountPoint.hashCode() : 0); return result; } @Override public String toString() { return "EfsMount{" + "efsId='" + efsId + '\'' + ", mountPoint='" + mountPoint + '\'' + ", mountPerm=" + mountPerm + ", efsRelativeMountPoint='" + efsRelativeMountPoint + '\'' + '}'; } public Builder toBuilder() { return newBuilder(this); } public static final class Builder { private String efsId; private String mountPoint; private EfsMount.MountPerm mountPerm; private String efsRelativeMountPoint; private Builder() { } public EfsMount.Builder withEfsId(String efsId) { this.efsId = efsId; return this; } public EfsMount.Builder withMountPoint(String mountPoint) { this.mountPoint = mountPoint; return this; } public EfsMount.Builder withMountPerm(EfsMount.MountPerm mountPerm) { this.mountPerm = mountPerm; return this; } public EfsMount.Builder withEfsRelativeMountPoint(String efsRelativeMountPoint) { this.efsRelativeMountPoint = efsRelativeMountPoint; return this; } public EfsMount.Builder but() { return newBuilder() .withEfsId(efsId) .withMountPoint(mountPoint) .withMountPerm(mountPerm) .withEfsRelativeMountPoint(efsRelativeMountPoint); } public EfsMount build() { return new EfsMount(efsId, mountPoint, mountPerm, efsRelativeMountPoint); } } }
9,629
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/TokenBucketPolicy.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import java.util.Objects; public class TokenBucketPolicy { private final long capacity; private final long initialNumberOfTokens; private final TokenBucketRefillPolicy refillPolicy; public TokenBucketPolicy(long capacity, long initialNumberOfTokens, TokenBucketRefillPolicy refillPolicy) { this.capacity = capacity; this.initialNumberOfTokens = initialNumberOfTokens; this.refillPolicy = refillPolicy; } public long getCapacity() { return capacity; } public long getInitialNumberOfTokens() { return initialNumberOfTokens; } public TokenBucketRefillPolicy getRefillPolicy() { return refillPolicy; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TokenBucketPolicy that = (TokenBucketPolicy) o; return capacity == that.capacity && initialNumberOfTokens == that.initialNumberOfTokens && Objects.equals(refillPolicy, that.refillPolicy); } @Override public int hashCode() { return Objects.hash(capacity, initialNumberOfTokens, refillPolicy); } @Override public String toString() { return "TokenBucketPolicy{" + "capacity=" + capacity + ", initialNumberOfTokens=" + initialNumberOfTokens + ", refillPolicy=" + refillPolicy + '}'; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private long capacity; private long initialNumberOfTokens; private TokenBucketRefillPolicy refillPolicy; private Builder() { } public Builder withCapacity(long capacity) { this.capacity = capacity; return this; } public Builder withInitialNumberOfTokens(long initialNumberOfTokens) { this.initialNumberOfTokens = initialNumberOfTokens; return this; } public Builder withRefillPolicy(TokenBucketRefillPolicy refillPolicy) { this.refillPolicy = refillPolicy; return this; } public TokenBucketPolicy build() { return new TokenBucketPolicy(capacity, initialNumberOfTokens, refillPolicy); } } }
9,630
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/MigrationPolicy.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = SelfManagedMigrationPolicy.class, name = "selfManaged"), }) public abstract class MigrationPolicy { }
9,631
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/ApplicationSLA.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model; import java.util.Objects; import com.google.common.base.Strings; import com.netflix.titus.common.util.StringExt; import static com.netflix.titus.api.model.SchedulerConstants.SCHEDULER_NAME_FENZO; import static com.netflix.titus.api.model.SchedulerConstants.SCHEDULER_NAME_KUBE_SCHEDULER; /** * Application SLA definition. */ public class ApplicationSLA { public static final String DEFAULT_CRITICAL_TIER_RESOURCE_POOL = "reserved"; public static final String DEFAULT_FLEX_TIER_RESOURCE_POOL = "elastic"; private final String appName; /** * If service tier is not defined it is defaulted to {@link Tier#Flex}. */ private final Tier tier; private final ResourceDimension resourceDimension; private final String schedulerName; private final String resourcePool; /** * Total number of instances required by this application. Titus will keep pre-allocated resources to always * fulfill this requirement. */ private int instanceCount; public ApplicationSLA(String appName, Tier tier, ResourceDimension resourceDimension, int instanceCount, String schedulerName, String resourcePool) { this.appName = appName; this.tier = tier; this.resourceDimension = resourceDimension; this.instanceCount = instanceCount; if (Strings.isNullOrEmpty(schedulerName)) { this.schedulerName = SCHEDULER_NAME_FENZO; } else { this.schedulerName = schedulerName; } // Resource pools are only used with Kube Scheduler. // Unless a non-empty value is given, we populate a default value of resource pool for non-GPU capacity groups // when associated with kubeScheduler such that // critical tier capacity groups (ApplicationSLAs) are mapped to reserved resource pool // and flex tier capacity groups are mapped to elastic. if (StringExt.isNotEmpty(resourcePool)) { this.resourcePool = resourcePool; } else { if (Objects.equals(this.schedulerName, SCHEDULER_NAME_KUBE_SCHEDULER) && this.resourceDimension.getGpu() == 0L) { if (tier == Tier.Critical) { this.resourcePool = DEFAULT_CRITICAL_TIER_RESOURCE_POOL; } else { this.resourcePool = DEFAULT_FLEX_TIER_RESOURCE_POOL; } } else { this.resourcePool = ""; } } } public String getAppName() { return appName; } public Tier getTier() { return tier; } public ResourceDimension getResourceDimension() { return resourceDimension; } public int getInstanceCount() { return instanceCount; } public String getResourcePool() { return resourcePool; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ApplicationSLA that = (ApplicationSLA) o; return instanceCount == that.instanceCount && Objects.equals(appName, that.appName) && tier == that.tier && Objects.equals(resourceDimension, that.resourceDimension) && Objects.equals(schedulerName, that.schedulerName) && Objects.equals(resourcePool, that.resourcePool); } @Override public int hashCode() { return Objects.hash(appName, tier, resourceDimension, schedulerName, resourcePool, instanceCount); } public String getSchedulerName() { return schedulerName; } @Override public String toString() { return "ApplicationSLA{" + "appName='" + appName + '\'' + ", tier=" + tier + ", resourceDimension=" + resourceDimension + ", schedulerName='" + schedulerName + '\'' + ", instanceCount=" + instanceCount + '\'' + ", resourcePool=" + resourcePool + '}'; } public static Builder newBuilder() { return new Builder(); } public static Builder newBuilder(ApplicationSLA original) { return newBuilder().withAppName(original.getAppName()).withTier(original.getTier()) .withResourceDimension(original.getResourceDimension()).withInstanceCount(original.getInstanceCount()) .withSchedulerName(original.getSchedulerName()) .withResourcePool(original.getResourcePool()); } public static final class Builder { private String appName; private Tier tier; private ResourceDimension resourceDimension; private int instanceCount; private String schedulerName; private String resourcePool; private Builder() { } public Builder withAppName(String appName) { this.appName = appName; return this; } public Builder withTier(Tier tier) { this.tier = tier; return this; } public Builder withResourceDimension(ResourceDimension resourceDimension) { this.resourceDimension = resourceDimension; return this; } public Builder withInstanceCount(int instanceCount) { this.instanceCount = instanceCount; return this; } public Builder but() { return newBuilder().withAppName(appName).withTier(tier) .withResourceDimension(resourceDimension).withInstanceCount(instanceCount); } public Builder withSchedulerName(String schedulerName) { this.schedulerName = schedulerName; return this; } public Builder withResourcePool(String resourcePool) { this.resourcePool = resourcePool; return this; } public ApplicationSLA build() { return new ApplicationSLA(appName, tier, resourceDimension, instanceCount, schedulerName, resourcePool); } } }
9,632
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/FailedScaleUpEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; public class FailedScaleUpEvent extends ScaleUpEvent { private final String errorMessage; public FailedScaleUpEvent(String instanceGroupId, int currentSize, int requestedSize, String errorMessage) { super(instanceGroupId, currentSize, requestedSize); this.errorMessage = errorMessage; } public String getErrorMessage() { return errorMessage; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } FailedScaleUpEvent that = (FailedScaleUpEvent) o; return errorMessage != null ? errorMessage.equals(that.errorMessage) : that.errorMessage == null; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (errorMessage != null ? errorMessage.hashCode() : 0); return result; } @Override public String toString() { return "FailedScaleUpEvent{" + "instanceGroupId='" + getInstanceGroupId() + '\'' + ", currentSize=" + getCurrentSize() + ", requestedSize=" + getRequestedSize() + ", errorMessage=" + errorMessage + '}'; } }
9,633
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/FailedScaleDownEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; import java.util.Collections; import java.util.Map; import java.util.Set; public class FailedScaleDownEvent extends ScaleDownEvent { private final Map<String, String> failures; private final String errorMessage; public FailedScaleDownEvent(String instanceGroupId, Set<String> terminatedInstanceIds, Map<String, String> failures) { super(instanceGroupId, terminatedInstanceIds); this.failures = failures; this.errorMessage = ""; } public FailedScaleDownEvent(String instanceGroupId, String errorMessage) { super(instanceGroupId, Collections.emptySet()); this.errorMessage = errorMessage; this.failures = Collections.emptyMap(); } public String getErrorMessage() { return errorMessage; } public Map<String, String> getFailures() { return failures; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } FailedScaleDownEvent that = (FailedScaleDownEvent) o; if (failures != null ? !failures.equals(that.failures) : that.failures != null) { return false; } return errorMessage != null ? errorMessage.equals(that.errorMessage) : that.errorMessage == null; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (failures != null ? failures.hashCode() : 0); result = 31 * result + (errorMessage != null ? errorMessage.hashCode() : 0); return result; } @Override public String toString() { return "FailedScaleDownEvent{" + "instanceGroupId='" + getInstanceGroupId() + ", errorMessage=" + errorMessage + ", terminatedInstanceIds=" + getTerminatedInstanceIds() + ", failures=" + failures + "} " + super.toString(); } }
9,634
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/UserRequestEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; /** * An event generated by */ public class UserRequestEvent { private final String operation; private final String callerId; private final String details; private final long timestamp; public UserRequestEvent(String operation, String callerId, String details, long timestamp) { this.operation = operation; this.callerId = callerId; this.details = details; this.timestamp = timestamp; } public String getOperation() { return operation; } public String getCallerId() { return callerId; } public String getDetails() { return details; } public long getTimestamp() { return timestamp; } }
9,635
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/ScaleDownEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; import java.util.Set; public class ScaleDownEvent extends AutoScaleEvent { private final Set<String> terminatedInstanceIds; public ScaleDownEvent(String instanceGroupId, Set<String> terminatedInstanceIds) { super(instanceGroupId); this.terminatedInstanceIds = terminatedInstanceIds; } public Set<String> getTerminatedInstanceIds() { return terminatedInstanceIds; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } ScaleDownEvent that = (ScaleDownEvent) o; return terminatedInstanceIds != null ? terminatedInstanceIds.equals(that.terminatedInstanceIds) : that.terminatedInstanceIds == null; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (terminatedInstanceIds != null ? terminatedInstanceIds.hashCode() : 0); return result; } @Override public String toString() { return "ScaleDownEvent{" + "instanceGroupId='" + getInstanceGroupId() + "terminatedInstanceIds=" + terminatedInstanceIds + "} " + super.toString(); } }
9,636
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/JobStateChangeEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; /** * Job state change event. */ public class JobStateChangeEvent<SOURCE> extends SchedulingEvent<SOURCE> { public enum JobState {Created, Resized, Activated, Deactivated, DisabledIncreaseDesired, DisabledDecreaseDesired, Finished} private final JobState jobState; public JobStateChangeEvent(String jobId, JobState jobState, long timestamp, SOURCE source) { super(jobId, timestamp, source); this.jobState = jobState; } public JobState getJobState() { return jobState; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } JobStateChangeEvent that = (JobStateChangeEvent) o; return jobState == that.jobState; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (jobState != null ? jobState.hashCode() : 0); return result; } @Override public String toString() { return "JobStateChangeEvent{" + "jobId='" + getJobId() + '\'' + ", jobState=" + jobState + ", timestamp=" + getTimestamp() + ", sourceType=" + getSource().getClass() + '}'; } }
9,637
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/TaskStateChangeEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; /** * Task state change event. */ public class TaskStateChangeEvent<SOURCE, STATE> extends SchedulingEvent<SOURCE> { private final String taskId; private final STATE state; public TaskStateChangeEvent(String jobId, String taskId, STATE state, long timestamp, SOURCE source) { super(jobId, timestamp, source); this.taskId = taskId; this.state = state; } public String getTaskId() { return taskId; } public STATE getState() { return state; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } TaskStateChangeEvent<?, ?> that = (TaskStateChangeEvent<?, ?>) o; if (taskId != null ? !taskId.equals(that.taskId) : that.taskId != null) { return false; } return state != null ? state.equals(that.state) : that.state == null; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (taskId != null ? taskId.hashCode() : 0); result = 31 * result + (state != null ? state.hashCode() : 0); return result; } @Override public String toString() { return "TaskStateChangeEvent{" + "jobId='" + getJobId() + '\'' + ", taskId='" + taskId + '\'' + ", state=" + state + ", timestamp=" + getTimestamp() + ", sourceType=" + getSource().getClass() + '}'; } }
9,638
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/SchedulingEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; /** * A base class for all scheduler events related to a particular job. */ public abstract class SchedulingEvent<SOURCE> { private final String jobId; private final long timestamp; private final SOURCE source; protected SchedulingEvent(String jobId, long timestamp, SOURCE source) { this.jobId = jobId; this.timestamp = timestamp; this.source = source; } public String getJobId() { return jobId; } public long getTimestamp() { return timestamp; } public SOURCE getSource() { return source; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } SchedulingEvent<?> that = (SchedulingEvent<?>) o; if (timestamp != that.timestamp) { return false; } if (jobId != null ? !jobId.equals(that.jobId) : that.jobId != null) { return false; } return source != null ? source.equals(that.source) : that.source == null; } @Override public int hashCode() { int result = jobId != null ? jobId.hashCode() : 0; result = 31 * result + (int) (timestamp ^ (timestamp >>> 32)); result = 31 * result + (source != null ? source.hashCode() : 0); return result; } }
9,639
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/AutoScaleEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; /** * Autoscaler base event type. */ public abstract class AutoScaleEvent { private final String instanceGroupId; protected AutoScaleEvent(String instanceGroupId) { this.instanceGroupId = instanceGroupId; } public String getInstanceGroupId() { return instanceGroupId; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AutoScaleEvent that = (AutoScaleEvent) o; return instanceGroupId != null ? instanceGroupId.equals(that.instanceGroupId) : that.instanceGroupId == null; } @Override public int hashCode() { return instanceGroupId != null ? instanceGroupId.hashCode() : 0; } @Override public String toString() { return "AutoScaleEvent{" + "instanceGroupId='" + instanceGroupId + '\'' + '}'; } }
9,640
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/event/ScaleUpEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.event; public class ScaleUpEvent extends AutoScaleEvent { private final float currentSize; private final int requestedSize; public ScaleUpEvent(String instanceGroupId, int currentSize, int requestedSize) { super(instanceGroupId); this.currentSize = currentSize; this.requestedSize = requestedSize; } public float getCurrentSize() { return currentSize; } public int getRequestedSize() { return requestedSize; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } ScaleUpEvent that = (ScaleUpEvent) o; if (Float.compare(that.currentSize, currentSize) != 0) { return false; } return requestedSize == that.requestedSize; } @Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (currentSize != +0.0f ? Float.floatToIntBits(currentSize) : 0); result = 31 * result + requestedSize; return result; } @Override public String toString() { return "ScaleUpEvent{" + "instanceGroupId='" + getInstanceGroupId() + "currentSize=" + currentSize + ", requestedSize=" + requestedSize + "}"; } }
9,641
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/reference/TierReference.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.reference; import java.util.Map; import java.util.Objects; import com.netflix.titus.api.model.Level; import com.netflix.titus.api.model.Tier; import static com.netflix.titus.common.util.CollectionsExt.newMapFrom; public class TierReference extends Reference { private static final Map<Tier, com.netflix.titus.api.model.reference.TierReference> TIER_REFERENCES = newMapFrom(Tier.values(), com.netflix.titus.api.model.reference.TierReference::new); private final Tier tier; public TierReference(Tier tier) { super(Level.Tier); this.tier = tier; } public Tier getTier() { return tier; } @Override public String getName() { return tier.name(); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } com.netflix.titus.api.model.reference.TierReference that = (com.netflix.titus.api.model.reference.TierReference) o; return tier == that.tier; } @Override public int hashCode() { return Objects.hash(tier); } @Override public String toString() { return "TierReference{" + "level=" + getLevel() + ", tier=" + tier + "} " + super.toString(); } public static TierReference getInstance(Tier tier) { return TIER_REFERENCES.get(tier); } }
9,642
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/reference/SystemReference.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.reference; import com.netflix.titus.api.model.Level; public class SystemReference extends Reference { private static final SystemReference INSTANCE = new SystemReference(); private SystemReference() { super(Level.System); } @Override public String getName() { return "system"; } @Override public String toString() { return "SystemReference{}"; } public static SystemReference getInstance() { return INSTANCE; } }
9,643
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/reference/TaskReference.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.reference; import java.util.Objects; import com.netflix.titus.api.model.Level; public class TaskReference extends Reference { private final String name; public TaskReference(String taskId) { super(Level.Task); this.name = taskId; } @Override public String getName() { return name; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } TaskReference that = (TaskReference) o; return Objects.equals(name, that.name); } @Override public int hashCode() { return Objects.hash(super.hashCode(), name); } @Override public String toString() { return "TaskReference{" + "name='" + name + '\'' + '}'; } }
9,644
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/reference/CapacityGroupReference.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.reference; import java.time.Duration; import java.util.Objects; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.netflix.titus.api.model.Level; public class CapacityGroupReference extends Reference { private static final LoadingCache<String, CapacityGroupReference> CACHE = Caffeine.newBuilder() .expireAfterWrite(Duration.ofHours(1)) .build(com.netflix.titus.api.model.reference.CapacityGroupReference::new); private final String name; private CapacityGroupReference(String name) { super(Level.CapacityGroup); this.name = name; } @Override public String getName() { return name; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } com.netflix.titus.api.model.reference.CapacityGroupReference that = (com.netflix.titus.api.model.reference.CapacityGroupReference) o; return Objects.equals(name, that.name); } @Override public int hashCode() { return Objects.hash(super.hashCode(), name); } @Override public String toString() { return "CapacityGroupReference{" + "level=" + getLevel() + ", name='" + name + '\'' + "} " + super.toString(); } public static CapacityGroupReference getInstance(String capacityGroupName) { return CACHE.get(capacityGroupName); } }
9,645
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/reference/Reference.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.reference; import java.util.Objects; import com.netflix.titus.api.model.Level; import com.netflix.titus.api.model.Tier; public abstract class Reference { private final Level level; protected Reference(Level level) { this.level = level; } public Level getLevel() { return level; } public abstract String getName(); @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Reference reference = (Reference) o; return level == reference.level; } @Override public int hashCode() { return Objects.hash(level); } public static Reference system() { return SystemReference.getInstance(); } public static Reference tier(Tier tier) { return TierReference.getInstance(tier); } public static Reference capacityGroup(String capacityGroupName) { return CapacityGroupReference.getInstance(capacityGroupName); } public static Reference job(String jobId) { return new JobReference(jobId); } public static Reference task(String taskId) { return new TaskReference(taskId); } }
9,646
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/model/reference/JobReference.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.model.reference; import java.util.Objects; import com.netflix.titus.api.model.Level; public class JobReference extends Reference { private final String name; public JobReference(String jobId) { super(Level.Job); this.name = jobId; } @Override public String getName() { return name; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!super.equals(o)) { return false; } JobReference that = (JobReference) o; return Objects.equals(name, that.name); } @Override public int hashCode() { return Objects.hash(super.hashCode(), name); } @Override public String toString() { return "JobReference{" + "name='" + name + '\'' + '}'; } }
9,647
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/IamConnector.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud; import com.netflix.titus.api.iam.model.IamRole; import reactor.core.publisher.Mono; /** * The primary API to interact with IAM cloud providers. */ public interface IamConnector { /** * Get an IAM Role descriptor. */ Mono<IamRole> getIamRole(String iamRoleName); /** * Returns a successful Mono if the specified IAM Role can be assumed * into by the provided assuming Role. */ Mono<Void> canIamAssume(String iamRoleName, String assumeResourceName); /** * Returns true if Titus agent can assume into the given role. */ Mono<Void> canAgentAssume(String iamRoleName); }
9,648
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/LoadBalancerConnector.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud; import java.util.Set; import rx.Completable; import rx.Single; public interface LoadBalancerConnector { /** * @param ipAddresses can be empty or null, in which case this is a noop. */ Completable registerAll(String loadBalancerId, Set<String> ipAddresses); /** * @param ipAddresses can be empty or null, in which case this is a noop. */ Completable deregisterAll(String loadBalancerId, Set<String> ipAddresses); /** * Checks if a load balancer ID is valid for use. */ Completable isValid(String loadBalancerId); Single<LoadBalancer> getLoadBalancer(String loadBalancerId); }
9,649
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/InstanceLaunchConfiguration.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud; public class InstanceLaunchConfiguration { private final String id; private final String instanceType; public InstanceLaunchConfiguration(String id, String instanceType) { this.id = id; this.instanceType = instanceType; } public String getId() { return id; } public String getInstanceType() { return instanceType; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } InstanceLaunchConfiguration that = (InstanceLaunchConfiguration) o; if (id != null ? !id.equals(that.id) : that.id != null) { return false; } return instanceType != null ? instanceType.equals(that.instanceType) : that.instanceType == null; } @Override public int hashCode() { int result = id != null ? id.hashCode() : 0; result = 31 * result + (instanceType != null ? instanceType.hashCode() : 0); return result; } @Override public String toString() { return "InstanceLaunchConfiguration{" + "id='" + id + '\'' + ", instanceType='" + instanceType + '\'' + '}'; } }
9,650
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/LoadBalancer.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud; import java.util.Collections; import java.util.Objects; import java.util.Set; public class LoadBalancer { public enum State { ACTIVE, REMOVED } private final String id; private final State state; private final Set<String> registeredIps; public LoadBalancer(String id, State state, Set<String> registeredIps) { this.id = id; this.state = state; this.registeredIps = Collections.unmodifiableSet(registeredIps); } public String getId() { return id; } public State getState() { return state; } public Set<String> getRegisteredIps() { return registeredIps; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof LoadBalancer)) { return false; } LoadBalancer that = (LoadBalancer) o; return id.equals(that.id) && state == that.state && registeredIps.equals(that.registeredIps); } @Override public int hashCode() { return Objects.hash(id, state, registeredIps); } @Override public String toString() { return "LoadBalancer{" + "id='" + id + '\'' + ", state=" + state + ", registeredIps=" + registeredIps + '}'; } }
9,651
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/CloudAlarmClient.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud; import java.util.List; import com.netflix.titus.api.appscale.model.AlarmConfiguration; import rx.Completable; import rx.Observable; public interface CloudAlarmClient { Observable<String> createOrUpdateAlarm(String policyRefId, String jobId, AlarmConfiguration alarmConfiguration, String autoScalingGroup, List<String> actions); Completable deleteAlarm(String policyRefId, String jobId); }
9,652
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/CloudConnectorException.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud; import java.util.Collection; public class CloudConnectorException extends RuntimeException { public enum ErrorCode { Internal, InvalidData, NotFound, } private final ErrorCode errorCode; private CloudConnectorException(ErrorCode errorCode, String message, Object[] args) { super(String.format(message, args)); this.errorCode = errorCode; } private CloudConnectorException(ErrorCode errorCode, String message) { super(message); this.errorCode = errorCode; } public ErrorCode getErrorCode() { return errorCode; } public static boolean isThis(Throwable cause, ErrorCode errorCode) { return cause instanceof CloudConnectorException && ((CloudConnectorException) cause).getErrorCode() == errorCode; } public static CloudConnectorException internalError(String message, Object... args) { return new CloudConnectorException(ErrorCode.Internal, message, args); } public static CloudConnectorException invalidInstanceGroupId(Collection<String> invalidIds) { return new CloudConnectorException(ErrorCode.NotFound, "Invalid instance group id(s): " + invalidIds); } public static CloudConnectorException unrecognizedInstanceType(String instanceType) { return new CloudConnectorException(ErrorCode.NotFound, "Unrecognized instance type: " + instanceType); } public static CloudConnectorException invalidArgument(String message, Object... args) { return new CloudConnectorException(ErrorCode.InvalidData, message, args); } public static CloudConnectorException unrecognizedTargetGroup(String targetGroup) { return new CloudConnectorException(ErrorCode.NotFound, "Unrecognized target group: " + targetGroup); } public static void checkArgument(boolean isValid, String message, Object... args) { if (isValid) { throw new CloudConnectorException(ErrorCode.InvalidData, message, args); } } }
9,653
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/AppAutoScalingClient.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud; import com.netflix.titus.api.appscale.model.AutoScalableTarget; import com.netflix.titus.api.appscale.model.PolicyConfiguration; import rx.Completable; import rx.Observable; public interface AppAutoScalingClient { Completable createScalableTarget(String jobId, int minCapacity, int maxCapacity); Observable<String> createOrUpdateScalingPolicy(String policyRefId, String jobId, PolicyConfiguration policyConfiguration); Completable deleteScalableTarget(String jobId); Completable deleteScalingPolicy(String policyRefId, String jobId); Observable<AutoScalableTarget> getScalableTargetsForJob(String jobId); }
9,654
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/noop/NoOpIamConnector.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud.noop; import com.netflix.titus.api.connector.cloud.IamConnector; import com.netflix.titus.api.iam.model.IamRole; import reactor.core.publisher.Mono; public class NoOpIamConnector implements IamConnector { @Override public Mono<IamRole> getIamRole(String iamRoleName) { return Mono.empty(); } @Override public Mono<Void> canIamAssume(String iamRoleName, String assumeResourceName) { return Mono.empty(); } @Override public Mono<Void> canAgentAssume(String iamRoleName) { return Mono.empty(); } }
9,655
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/noop/NoOpLoadBalancerConnector.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud.noop; import java.util.Collections; import java.util.Set; import com.netflix.titus.api.connector.cloud.LoadBalancer; import com.netflix.titus.api.connector.cloud.LoadBalancerConnector; import rx.Completable; import rx.Single; /** * Test helper class that intentionally does nothing on register/deregister and returns success. */ public class NoOpLoadBalancerConnector implements LoadBalancerConnector { @Override public Completable registerAll(String loadBalancerId, Set<String> ipAddresses) { return Completable.complete(); } @Override public Completable deregisterAll(String loadBalancerId, Set<String> ipAddresses) { return Completable.complete(); } @Override public Completable isValid(String loadBalancerId) { return Completable.complete(); } @Override public Single<LoadBalancer> getLoadBalancer(String id) { return Single.just(new LoadBalancer(id, LoadBalancer.State.REMOVED, Collections.emptySet())); } }
9,656
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/noop/NoOpAppAutoScalingClient.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud.noop; import com.netflix.titus.api.appscale.model.AutoScalableTarget; import com.netflix.titus.api.appscale.model.PolicyConfiguration; import com.netflix.titus.api.connector.cloud.AppAutoScalingClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import rx.Completable; import rx.Observable; public class NoOpAppAutoScalingClient implements AppAutoScalingClient { private static Logger log = LoggerFactory.getLogger(NoOpAppAutoScalingClient.class); @Override public Completable createScalableTarget(String jobId, int minCapacity, int maxCapacity) { log.info("Created scalable target for job {}", jobId); return Completable.complete(); } @Override public Observable<String> createOrUpdateScalingPolicy(String policyRefId, String jobId, PolicyConfiguration policyConfiguration) { log.info("Created/Updated scaling policy {} - for job {}", policyRefId, jobId); return Observable.just(policyRefId); } @Override public Completable deleteScalableTarget(String jobId) { log.info("Deleted scalable target for job {}", jobId); return Completable.complete(); } @Override public Completable deleteScalingPolicy(String policyRefId, String jobId) { log.info("Deleted scaling policy {} for job {}", policyRefId, jobId); return Completable.complete(); } @Override public Observable<AutoScalableTarget> getScalableTargetsForJob(String jobId) { AutoScalableTarget autoScalableTarget = AutoScalableTarget.newBuilder() .withMinCapacity(1) .withMaxCapacity(10) .build(); log.info("Scalable targets for JobId {} - {}", jobId, autoScalableTarget); return Observable.just(autoScalableTarget); } }
9,657
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/connector/cloud/noop/NoOpCloudAlarmClient.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.connector.cloud.noop; import java.util.List; import com.netflix.titus.api.appscale.model.AlarmConfiguration; import com.netflix.titus.api.connector.cloud.CloudAlarmClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import rx.Completable; import rx.Observable; public class NoOpCloudAlarmClient implements CloudAlarmClient { private static Logger log = LoggerFactory.getLogger(NoOpCloudAlarmClient.class); @Override public Observable<String> createOrUpdateAlarm(String policyRefId, String jobId, AlarmConfiguration alarmConfiguration, String autoScalingGroup, List<String> actions) { String alarmName = buildAlarmName(policyRefId, jobId); log.info("Created Alarm {}", alarmName); return Observable.just(alarmName); } @Override public Completable deleteAlarm(String policyRefId, String jobId) { log.info("Deleted Alarm {}", buildAlarmName(policyRefId, jobId)); return Completable.complete(); } private String buildAlarmName(String policyRefId, String jobId) { return String.format("%s/%s", jobId, policyRefId); } }
9,658
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/service/TitusServiceException.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.service; import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import com.netflix.titus.common.model.sanitizer.ValidationError; import com.netflix.titus.common.util.StringExt; import static java.lang.String.format; /** * A custom runtime exception that indicates an error in the service layer and will propagate to transport layer. */ public class TitusServiceException extends RuntimeException { public enum ErrorCode { INTERNAL, NO_CALLER_ID, JOB_NOT_FOUND, TASK_NOT_FOUND, UNEXPECTED, INVALID_PAGE_OFFSET, INVALID_ARGUMENT, CELL_NOT_FOUND, INVALID_JOB } private final ErrorCode errorCode; private final Set<? extends ValidationError> validationErrors; private TitusServiceException(TitusServiceExceptionBuilder builder) { super(builder.message, builder.cause); this.errorCode = builder.errorCode; this.validationErrors = builder.validationErrors; } public static TitusServiceExceptionBuilder newBuilder(ErrorCode errorCode, String message) { return new TitusServiceExceptionBuilder(errorCode, message); } public ErrorCode getErrorCode() { return errorCode; } public Set<? extends ValidationError> getValidationErrors() { return validationErrors; } public static final class TitusServiceExceptionBuilder { ErrorCode errorCode; String message; Throwable cause; Set<? extends ValidationError> validationErrors; private TitusServiceExceptionBuilder(ErrorCode errorCode, String message) { this.errorCode = errorCode; this.message = message; } public TitusServiceExceptionBuilder withCause(Throwable cause) { this.cause = cause; return this; } public TitusServiceExceptionBuilder withValidationErrors(Set<? extends ValidationError> constraintViolations) { this.validationErrors = constraintViolations; return this; } public TitusServiceException build() { if (this.validationErrors == null) { this.validationErrors = Collections.emptySet(); } return new TitusServiceException(this); } } public static TitusServiceException jobNotFound(String jobId) { return jobNotFound(jobId, null); } public static TitusServiceException jobNotFound(String jobId, Throwable cause) { return TitusServiceException.newBuilder(ErrorCode.JOB_NOT_FOUND, format("Job id %s not found", jobId)) .withCause(cause) .build(); } public static TitusServiceException taskNotFound(String taskId) { return taskNotFound(taskId, null); } public static TitusServiceException taskNotFound(String taskId, Throwable cause) { return TitusServiceException.newBuilder(ErrorCode.TASK_NOT_FOUND, format("Task id %s not found", taskId)) .withCause(cause) .build(); } public static TitusServiceException invalidArgument(String message) { return TitusServiceException.newBuilder(ErrorCode.INVALID_ARGUMENT, message).build(); } public static TitusServiceException invalidArgument(Throwable e) { return TitusServiceException.newBuilder(ErrorCode.INVALID_ARGUMENT, e.getMessage()).withCause(e).build(); } public static TitusServiceException invalidArgument(Set<? extends ValidationError> validationErrors) { return invalidArgument("", validationErrors); } public static TitusServiceException invalidArgument(String context, Set<? extends ValidationError> validationErrors) { String errors = validationErrors.stream() .map(err -> String.format("{%s}", err)) .collect(Collectors.joining(", ")); String errMsg = String.format("Invalid Argument: %s", errors); if (StringExt.isNotEmpty(context)) { errMsg = context + ". " + errMsg; } return TitusServiceException.newBuilder(ErrorCode.INVALID_ARGUMENT, errMsg) .withValidationErrors(validationErrors) .build(); } /** * Creates a {@link TitusServiceException} encapsulating {@link ValidationError}s. * * @param validationErrors The errors to be encapsulated by the exception * @return A {@link TitusServiceException} encapsulating the appropriate errors. */ public static TitusServiceException invalidJob(Set<ValidationError> validationErrors) { String errors = validationErrors.stream() .map(err -> String.format("{%s}", err)) .collect(Collectors.joining(", ")); String errMsg = String.format("Invalid Job: %s", errors); return TitusServiceException.newBuilder(ErrorCode.INVALID_JOB, errMsg).build(); } public static TitusServiceException unexpected(String message, Object... args) { return unexpected(null, message, args); } public static TitusServiceException unexpected(Throwable cause, String message, Object... args) { return TitusServiceException.newBuilder(ErrorCode.UNEXPECTED, format(message, args)) .withCause(cause) .build(); } public static TitusServiceException internal(String message, Object... args) { return internal(null, message, args); } public static TitusServiceException internal(Throwable cause, String message, Object... args) { return TitusServiceException.newBuilder(ErrorCode.INTERNAL, format(message, args)) .withCause(cause) .build(); } public static TitusServiceException noCallerId() { return TitusServiceException.newBuilder(ErrorCode.NO_CALLER_ID, "Caller's id not found").build(); } public static TitusServiceException cellNotFound(String cellName) { return TitusServiceException.newBuilder(ErrorCode.CELL_NOT_FOUND, format("Could not find Titus Cell %s", cellName)).build(); } }
9,659
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/ComparisonOperator.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public enum ComparisonOperator { GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanOrEqualToThreshold, LessThanThreshold }
9,660
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/StepAdjustment.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import java.util.Optional; public class StepAdjustment { private final int scalingAdjustment; private final Optional<Double> metricIntervalLowerBound; private final Optional<Double> metricIntervalUpperBound; public StepAdjustment(int scalingAdjustment, Optional<Double> metricIntervalLowerBound, Optional<Double> metricIntervalUpperBound) { this.scalingAdjustment = scalingAdjustment; this.metricIntervalLowerBound = metricIntervalLowerBound; this.metricIntervalUpperBound = metricIntervalUpperBound; } public int getScalingAdjustment() { return scalingAdjustment; } public Optional<Double> getMetricIntervalLowerBound() { return metricIntervalLowerBound; } public Optional<Double> getMetricIntervalUpperBound() { return metricIntervalUpperBound; } public static Builder newBuilder() { return new Builder(); } public static class Builder { private int scalingAdjustment; private Optional<Double> metricIntervalLowerBound = Optional.empty(); private Optional<Double> metricIntervalUpperBound = Optional.empty(); private Builder() { } public Builder withScalingAdjustment(int scalingAdjustment) { this.scalingAdjustment = scalingAdjustment; return this; } public Builder withMetricIntervalLowerBound(double metricIntervalLowerBound) { this.metricIntervalLowerBound = Optional.of(metricIntervalLowerBound); return this; } public Builder withMetricIntervalUpperBound(double metricIntervalUpperBound) { this.metricIntervalUpperBound = Optional.of(metricIntervalUpperBound); return this; } public StepAdjustment build() { return new StepAdjustment(scalingAdjustment, metricIntervalLowerBound, metricIntervalUpperBound); } } }
9,661
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/PolicyType.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public enum PolicyType { StepScaling, TargetTrackingScaling }
9,662
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/AlarmConfiguration.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import java.util.Collections; import java.util.List; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonProperty; public class AlarmConfiguration { private final String name; private final String region; private final Optional<Boolean> actionsEnabled; private final ComparisonOperator comparisonOperator; private final int evaluationPeriods; private final int periodSec; private final double threshold; private final String metricNamespace; private final String metricName; private final Statistic statistic; private final List<MetricDimension> dimensions; public AlarmConfiguration(String name, String region, Optional<Boolean> actionsEnabled, ComparisonOperator comparisonOperator, int evaluationPeriods, int periodSec, double threshold, String metricNamespace, String metricName, Statistic statistic, List<MetricDimension> dimensions) { this.name = name; this.region = region; this.actionsEnabled = actionsEnabled; // TODO(Andrew L): Change the parameter this.comparisonOperator = comparisonOperator; this.evaluationPeriods = evaluationPeriods; this.periodSec = periodSec; this.threshold = threshold; this.metricNamespace = metricNamespace; this.metricName = metricName; this.statistic = statistic; this.dimensions = dimensions; } @JsonProperty public String getRegion() { return region; } @JsonProperty public String getName() { return name; } @JsonProperty public Optional<Boolean> getActionsEnabled() { return actionsEnabled; } @JsonProperty public ComparisonOperator getComparisonOperator() { return comparisonOperator; } @JsonProperty public int getEvaluationPeriods() { return evaluationPeriods; } @JsonProperty public int getPeriodSec() { return periodSec; } @JsonProperty public double getThreshold() { return threshold; } @JsonProperty public String getMetricNamespace() { return metricNamespace; } @JsonProperty public String getMetricName() { return metricName; } @JsonProperty public Statistic getStatistic() { return statistic; } @JsonProperty public List<MetricDimension> getDimensions() { return dimensions; } @Override public String toString() { return "AlarmConfiguration{" + "name='" + name + '\'' + ", region='" + region + '\'' + ", actionsEnabled=" + actionsEnabled + ", comparisonOperator=" + comparisonOperator + ", evaluationPeriods=" + evaluationPeriods + ", periodSec=" + periodSec + ", threshold=" + threshold + ", metricNamespace='" + metricNamespace + '\'' + ", metricName='" + metricName + '\'' + ", statistic=" + statistic + '\n' + ", dimensions=" + dimensions + '}'; } public static Builder newBuilder() { return new Builder(); } public static class Builder { private String name; private String region; private Optional<Boolean> actionsEnabled = Optional.empty(); private ComparisonOperator comparisonOperator; private int evaluationPeriods; private int periodSec; private double threshold; private String metricNamespace; private String metricName; private Statistic statistic; private List<MetricDimension> dimensions = Collections.emptyList(); private Builder() { } public Builder withName(String name) { this.name = name; return this; } public Builder withRegion(String region) { this.region = region; return this; } public Builder withActionsEnabled(Boolean actionsEnabled) { this.actionsEnabled = Optional.of(actionsEnabled); return this; } public Builder withComparisonOperator(ComparisonOperator comparisonOperator) { this.comparisonOperator = comparisonOperator; return this; } public Builder withEvaluationPeriods(int evaluationPeriods) { this.evaluationPeriods = evaluationPeriods; return this; } public Builder withPeriodSec(int periodSec) { this.periodSec = periodSec; return this; } public Builder withThreshold(double threshold) { this.threshold = threshold; return this; } public Builder withMetricNamespace(String metricNamespace) { this.metricNamespace = metricNamespace; return this; } public Builder withMetricName(String metricName) { this.metricName = metricName; return this; } public Builder withStatistic(Statistic staticstic) { this.statistic = staticstic; return this; } public Builder withDimensions(List<MetricDimension> dimensions) { this.dimensions = dimensions; return this; } public AlarmConfiguration build() { return new AlarmConfiguration(name, region, actionsEnabled, comparisonOperator, evaluationPeriods, periodSec, threshold, metricNamespace, metricName, statistic, dimensions); } } }
9,663
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/StepScalingPolicyConfiguration.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import java.util.ArrayList; import java.util.List; import java.util.Optional; public class StepScalingPolicyConfiguration { private final Optional<Integer> coolDownSec; private final Optional<MetricAggregationType> metricAggregationType; private final Optional<StepAdjustmentType> adjustmentType; private final Optional<Long> minAdjustmentMagnitude; private final List<StepAdjustment> steps; public StepScalingPolicyConfiguration(Optional<Integer> coolDownSec, Optional<MetricAggregationType> metricAggregationType, Optional<StepAdjustmentType> adjustmentType, Optional<Long> minAdjustmentMagnitude, List<StepAdjustment> steps) { this.coolDownSec = coolDownSec; this.metricAggregationType = metricAggregationType; this.adjustmentType = adjustmentType; this.minAdjustmentMagnitude = minAdjustmentMagnitude; this.steps = steps; } public Optional<Integer> getCoolDownSec() { return coolDownSec; } public Optional<MetricAggregationType> getMetricAggregationType() { return metricAggregationType; } public Optional<StepAdjustmentType> getAdjustmentType() { return adjustmentType; } public Optional<Long> getMinAdjustmentMagnitude() { return minAdjustmentMagnitude; } public List<StepAdjustment> getSteps() { return steps; } @Override public String toString() { return "StepScalingPolicyConfiguration{" + "coolDownSec=" + coolDownSec + ", metricAggregationType=" + metricAggregationType + ", adjustmentType=" + adjustmentType + ", minAdjustmentMagnitude=" + minAdjustmentMagnitude + ", steps=" + steps + '}'; } public static Builder newBuilder() { return new Builder(); } public static class Builder { private Optional<Integer> coolDownSec = Optional.empty(); private Optional<MetricAggregationType> metricAggregationType = Optional.empty(); private Optional<StepAdjustmentType> adjustmentType = Optional.empty(); private Optional<Long> minAdjustmentMagnitude = Optional.empty(); private List<StepAdjustment> steps = new ArrayList<>(); private Builder() { } public Builder withCoolDownSec(Integer coolDownSec) { this.coolDownSec = Optional.of(coolDownSec); return this; } public Builder withMetricAggregatorType(MetricAggregationType metricAggregatorType) { this.metricAggregationType = Optional.of(metricAggregatorType); return this; } public Builder withAdjustmentType(StepAdjustmentType stepAdjustmentType) { this.adjustmentType = Optional.of(stepAdjustmentType); return this; } public Builder withMinAdjustmentMagnitude(long minAdjustmentMagnitude) { this.minAdjustmentMagnitude = Optional.of(minAdjustmentMagnitude); return this; } public Builder withSteps(List<StepAdjustment> steps) { this.steps = steps; return this; } public StepScalingPolicyConfiguration build() { return new StepScalingPolicyConfiguration(coolDownSec, metricAggregationType, adjustmentType, minAdjustmentMagnitude, steps); } } }
9,664
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/CustomizedMetricSpecification.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import java.util.ArrayList; import java.util.List; import java.util.Optional; public class CustomizedMetricSpecification { private final List<MetricDimension> metricDimensionList; private final String metricName; private final String namespace; private final Statistic statistic; private final Optional<String> unit; public CustomizedMetricSpecification(List<MetricDimension> metricDimensionList, String metricName, String namespace, Statistic statistic, Optional<String> unit) { this.metricDimensionList = metricDimensionList; this.metricName = metricName; this.namespace = namespace; this.statistic = statistic; this.unit = unit; } public List<MetricDimension> getMetricDimensionList() { return metricDimensionList; } public String getMetricName() { return metricName; } public String getNamespace() { return namespace; } public Statistic getStatistic() { return statistic; } public Optional<String> getUnit() { return unit; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private List<MetricDimension> metricDimensionList = new ArrayList<>(); private String metricName; private String namespace; private Statistic statistic; private Optional<String> unit = Optional.empty(); private Builder() { } public static Builder aCustomizedMetricSpecification() { return new Builder(); } public Builder withMetricDimensionList(List<MetricDimension> metricDimensionList) { this.metricDimensionList = metricDimensionList; return this; } public Builder withMetricName(String metricName) { this.metricName = metricName; return this; } public Builder withNamespace(String namespace) { this.namespace = namespace; return this; } public Builder withStatistic(Statistic statistic) { this.statistic = statistic; return this; } public Builder withUnit(String unit) { this.unit = Optional.of(unit); return this; } public CustomizedMetricSpecification build() { return new CustomizedMetricSpecification(metricDimensionList, metricName, namespace, statistic, unit); } } }
9,665
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/Statistic.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public enum Statistic { Sum, Minimum, Maximum, Average, SampleCount }
9,666
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/StepAdjustmentType.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public enum StepAdjustmentType { ChangeInCapacity, PercentChangeInCapacity, ExactCapacity }
9,667
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/MetricAggregationType.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public enum MetricAggregationType { Average, Minimum, Maximum }
9,668
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/MetricDimension.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import com.fasterxml.jackson.annotation.JsonProperty; public class MetricDimension { private String name; private String value; public MetricDimension(String name, String value) { this.name = name; this.value = value; } @JsonProperty public String getName() { return name; } @JsonProperty public String getValue() { return value; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private String name; private String value; private Builder() { } public static Builder aMetricDimension() { return new Builder(); } public Builder withName(String name) { this.name = name; return this; } public Builder withValue(String value) { this.value = value; return this; } public MetricDimension build() { return new MetricDimension(name, value); } } }
9,669
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/AutoScalingPolicy.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import com.netflix.titus.common.model.sanitizer.ClassInvariant; @ClassInvariant(expr = "@asserts.validateScalingPolicy(#this)") public class AutoScalingPolicy { private final String refId; private final PolicyConfiguration policyConfiguration; private final String jobId; private final String policyId; private final String alarmId; private final PolicyStatus status; private final String statusMessage; public AutoScalingPolicy(String refId, String jobId, PolicyConfiguration policyConfiguration, String policyId, String alarmId, PolicyStatus status, String statusMessage) { this.refId = refId; this.jobId = jobId; this.policyConfiguration = policyConfiguration; this.alarmId = alarmId; this.status = status; this.policyId = policyId; this.statusMessage = statusMessage; } public String getJobId() { return jobId; } public String getRefId() { return refId; } public PolicyConfiguration getPolicyConfiguration() { return policyConfiguration; } public String getPolicyId() { return policyId; } public String getAlarmId() { return alarmId; } public PolicyStatus getStatus() { return status; } public String getStatusMessage() { return statusMessage; } public static Builder newBuilder() { return new Builder(); } @Override public String toString() { return "AutoScalingPolicy{" + "refId='" + refId + '\'' + ", policyConfiguration=" + policyConfiguration + ", policyId='" + policyId + '\'' + ", alarmId='" + alarmId + '\'' + ", status=" + status + '}'; } public static class Builder { private String refId; private String jobId; private PolicyConfiguration policyConfiguration; private String policyId; private String alarmId; private PolicyStatus status; private String statusMessage; private Builder() { } public Builder withAutoScalingPolicy(AutoScalingPolicy other) { this.refId = other.refId; this.jobId = other.jobId; this.policyConfiguration = other.policyConfiguration; // shallow copy OK since immutable this.alarmId = other.alarmId; this.status = other.status; this.policyId = other.policyId; this.statusMessage = other.statusMessage; return this; } public Builder withJobId(String jobId) { this.jobId = jobId; return this; } public Builder withRefId(String refId) { this.refId = refId; return this; } public Builder withPolicyConfiguration(PolicyConfiguration policyConfiguration) { this.policyConfiguration = policyConfiguration; return this; } public Builder withPolicyId(String policyId) { this.policyId = policyId; return this; } public Builder withAlarmId(String alarmId) { this.alarmId = alarmId; return this; } public Builder withStatus(PolicyStatus policyStatus) { this.status = policyStatus; return this; } public Builder withStatusMessage(String statusMessage) { this.statusMessage = statusMessage; return this; } public AutoScalingPolicy build() { return new AutoScalingPolicy(refId, jobId, policyConfiguration, policyId, alarmId, status, statusMessage); } } }
9,670
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/PolicyStatus.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public enum PolicyStatus { Pending, Applied, Deleting, Deleted, Error }
9,671
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/PredefinedMetricSpecification.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import java.util.Optional; public class PredefinedMetricSpecification { private final String predefinedMetricType; private final Optional<String> resourceLabel; public PredefinedMetricSpecification(String predefinedMetricType, Optional<String> resourceLabel) { this.predefinedMetricType = predefinedMetricType; this.resourceLabel = resourceLabel; } public String getPredefinedMetricType() { return predefinedMetricType; } public Optional<String> getResourceLabel() { return resourceLabel; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private String predefinedMetricType; private Optional<String> resourceLabel = Optional.empty(); private Builder() { } public Builder withPredefinedMetricType(String predefinedMetricType) { this.predefinedMetricType = predefinedMetricType; return this; } public Builder withResourceLabel(String resourceLabel) { this.resourceLabel = Optional.of(resourceLabel); return this; } public PredefinedMetricSpecification build() { return new PredefinedMetricSpecification(predefinedMetricType, resourceLabel); } } }
9,672
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/AutoScalableTarget.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public class AutoScalableTarget { private final String resourceId; private final int minCapacity; private final int maxCapacity; public AutoScalableTarget(String resourceId, int minCapacity, int maxCapacity) { this.resourceId = resourceId; this.minCapacity = minCapacity; this.maxCapacity = maxCapacity; } public String getResourceId() { return resourceId; } public int getMinCapacity() { return minCapacity; } public int getMaxCapacity() { return maxCapacity; } public static Builder newBuilder() { return new Builder(); } public static class Builder { private String resourceId; private int minCapacity; private int maxCapacity; private Builder() { } public Builder withResourceId(String resourceId) { this.resourceId = resourceId; return this; } public Builder withMinCapacity(int minCapacity) { this.minCapacity = minCapacity; return this; } public Builder withMaxCapacity(int maxCapacity) { this.maxCapacity = maxCapacity; return this; } public AutoScalableTarget build() { return new AutoScalableTarget(this.resourceId, this.minCapacity, this.maxCapacity); } } @Override public String toString() { return "AutoScalableTarget{" + "resourceId='" + resourceId + '\'' + ", minCapacity=" + minCapacity + ", maxCapacity=" + maxCapacity + '}'; } }
9,673
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/TargetTrackingPolicy.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; import java.util.Optional; public class TargetTrackingPolicy { private final double targetValue; private final Optional<Integer> scaleOutCooldownSec; private final Optional<Integer> scaleInCooldownSec; private final Optional<PredefinedMetricSpecification> predefinedMetricSpecification; private final Optional<Boolean> disableScaleIn; private final Optional<CustomizedMetricSpecification> customizedMetricSpecification; public TargetTrackingPolicy(double targetValue, Optional<Integer> scaleOutCooldownSec, Optional<Integer> scaleInCooldownSec, Optional<PredefinedMetricSpecification> predefinedMetricSpecification, Optional<Boolean> disableScaleIn, Optional<CustomizedMetricSpecification> customizedMetricSpecification) { this.targetValue = targetValue; this.scaleOutCooldownSec = scaleOutCooldownSec; this.scaleInCooldownSec = scaleInCooldownSec; this.predefinedMetricSpecification = predefinedMetricSpecification; this.disableScaleIn = disableScaleIn; this.customizedMetricSpecification = customizedMetricSpecification; } public double getTargetValue() { return targetValue; } public Optional<Integer> getScaleOutCooldownSec() { return scaleOutCooldownSec; } public Optional<Integer> getScaleInCooldownSec() { return scaleInCooldownSec; } public Optional<PredefinedMetricSpecification> getPredefinedMetricSpecification() { return predefinedMetricSpecification; } public Optional<Boolean> getDisableScaleIn() { return disableScaleIn; } public Optional<CustomizedMetricSpecification> getCustomizedMetricSpecification() { return customizedMetricSpecification; } @Override public String toString() { return "TargetTrackingPolicy{" + "targetValue=" + targetValue + ", scaleOutCooldownSec=" + scaleOutCooldownSec + ", scaleInCooldownSec=" + scaleInCooldownSec + ", predefinedMetricSpecification=" + predefinedMetricSpecification + ", disableScaleIn=" + disableScaleIn + ", customizedMetricSpecification=" + customizedMetricSpecification + '}'; } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private double targetValue; private Optional<Integer> scaleOutCooldownSec = Optional.empty(); private Optional<Integer> scaleInCooldownSec = Optional.empty(); private Optional<PredefinedMetricSpecification> predefinedMetricSpecification = Optional.empty(); private Optional<Boolean> disableScaleIn = Optional.empty(); private Optional<CustomizedMetricSpecification> customizedMetricSpecification = Optional.empty(); private Builder() { } public static Builder aTargetTrackingPolicy() { return new Builder(); } public Builder withTargetValue(double targetValue) { this.targetValue = targetValue; return this; } public Builder withScaleOutCooldownSec(Integer scaleOutCooldownSec) { this.scaleOutCooldownSec = Optional.of(scaleOutCooldownSec); return this; } public Builder withScaleInCooldownSec(Integer scaleInCooldownSec) { this.scaleInCooldownSec = Optional.of(scaleInCooldownSec); return this; } public Builder withPredefinedMetricSpecification(PredefinedMetricSpecification predefinedMetricSpecification) { this.predefinedMetricSpecification = Optional.of(predefinedMetricSpecification); return this; } public Builder withDisableScaleIn(Boolean disableScaleIn) { this.disableScaleIn = Optional.of(disableScaleIn); return this; } public Builder withCustomizedMetricSpecification(CustomizedMetricSpecification customizedMetricSpecification) { this.customizedMetricSpecification = Optional.of(customizedMetricSpecification); return this; } public TargetTrackingPolicy build() { return new TargetTrackingPolicy(targetValue, scaleOutCooldownSec, scaleInCooldownSec, predefinedMetricSpecification, disableScaleIn, customizedMetricSpecification); } } }
9,674
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/PolicyConfiguration.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model; public class PolicyConfiguration { private final String name; private final PolicyType policyType; private final StepScalingPolicyConfiguration stepScalingPolicyConfiguration; private final AlarmConfiguration alarmConfiguration; private final TargetTrackingPolicy targetTrackingPolicy; public PolicyConfiguration(String name, PolicyType policyType, StepScalingPolicyConfiguration stepScalingPolicyConfiguration, AlarmConfiguration alarmConfiguration, TargetTrackingPolicy targetTrackingPolicy) { this.name = name; this.policyType = policyType; this.stepScalingPolicyConfiguration = stepScalingPolicyConfiguration; this.alarmConfiguration = alarmConfiguration; this.targetTrackingPolicy = targetTrackingPolicy; } public String getName() { return name; } public PolicyType getPolicyType() { return policyType; } public StepScalingPolicyConfiguration getStepScalingPolicyConfiguration() { return stepScalingPolicyConfiguration; } public AlarmConfiguration getAlarmConfiguration() { return alarmConfiguration; } public TargetTrackingPolicy getTargetTrackingPolicy() { return targetTrackingPolicy; } @Override public String toString() { return "PolicyConfiguration{" + "name='" + name + '\'' + ", policyType=" + policyType + ", stepScalingPolicyConfiguration=" + stepScalingPolicyConfiguration + ", alarmConfiguration=" + alarmConfiguration + ", targetTrackingPolicy=" + targetTrackingPolicy + '}'; } public static Builder newBuilder() { return new Builder(); } public static class Builder { private String name; private PolicyType policyType; private StepScalingPolicyConfiguration stepScalingPolicyConfiguration; private AlarmConfiguration alarmConfiguration; private TargetTrackingPolicy targetTrackingPolicy; private Builder() { } public Builder withName(String name) { this.name = name; return this; } public Builder withPolicyType(PolicyType policyType) { this.policyType = policyType; return this; } public Builder withStepScalingPolicyConfiguration(StepScalingPolicyConfiguration stepScalingPolicyConfiguration) { this.stepScalingPolicyConfiguration = stepScalingPolicyConfiguration; return this; } public Builder withAlarmConfiguration(AlarmConfiguration alarmConfiguration) { this.alarmConfiguration = alarmConfiguration; return this; } public Builder withTargetTrackingPolicy(TargetTrackingPolicy targetTrackingPolicy) { this.targetTrackingPolicy = targetTrackingPolicy; return this; } public PolicyConfiguration build() { return new PolicyConfiguration(name, policyType, stepScalingPolicyConfiguration, alarmConfiguration, targetTrackingPolicy); } } }
9,675
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/sanitizer/ScalingPolicyAssertions.java
/* * Copyright 2021 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model.sanitizer; import java.util.Collections; import java.util.HashMap; import java.util.Map; import com.netflix.titus.api.appscale.model.AutoScalingPolicy; import com.netflix.titus.api.appscale.model.PolicyConfiguration; public class ScalingPolicyAssertions { public Map<String, String> validateScalingPolicy(AutoScalingPolicy autoScalingPolicy) { if (autoScalingPolicy == null || autoScalingPolicy.getPolicyConfiguration() == null) { return Collections.emptyMap(); } PolicyConfiguration policyConfiguration = autoScalingPolicy.getPolicyConfiguration(); Map<String, String> violations = new HashMap<>(); if ((policyConfiguration.getStepScalingPolicyConfiguration() != null) == (policyConfiguration.getTargetTrackingPolicy() != null)) { violations.put("scalingPolicies", "exactly one scaling policy should be set"); } if (policyConfiguration.getStepScalingPolicyConfiguration() != null && policyConfiguration.getAlarmConfiguration() == null) { violations.put("alarmConfiguration", "alarmConfiguration must be specified for a step scaling policy"); } return violations; } }
9,676
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/model/sanitizer/ScalingPolicySanitizerBuilder.java
/* * Copyright 2021 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.model.sanitizer; import com.netflix.titus.common.model.sanitizer.EntitySanitizer; import com.netflix.titus.common.model.sanitizer.EntitySanitizerBuilder; public class ScalingPolicySanitizerBuilder { public static final String SCALING_POLICY_SANITIZER = "scalingPolicySanitizer"; private final EntitySanitizerBuilder sanitizerBuilder = EntitySanitizerBuilder.stdBuilder(); public EntitySanitizer build() { return sanitizerBuilder.registerBean("asserts", new ScalingPolicyAssertions()).build(); } }
9,677
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/service/AutoScalePolicyException.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.service; import com.netflix.titus.api.jobmanager.service.JobManagerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class AutoScalePolicyException extends RuntimeException { private static Logger log = LoggerFactory.getLogger(AutoScalePolicyException.class); public enum ErrorCode { JobManagerError, InvalidScalingPolicy, UnknownScalingPolicy, ErrorCreatingPolicy, ErrorCreatingTarget, ErrorCreatingAlarm, ErrorDeletingPolicy, ErrorDeletingTarget, ErrorDeletingAlarm, ErrorUpdatingTargets, UnexpectedError, } private String policyRefId; private String jobId; private final ErrorCode errorCode; private AutoScalePolicyException(ErrorCode errorCode, String message) { this(errorCode, message, new RuntimeException(message)); } private AutoScalePolicyException(ErrorCode errorCode, String message, String policyRefId, String jobId) { super(message); this.policyRefId = policyRefId; this.jobId = jobId; this.errorCode = errorCode; } private AutoScalePolicyException(ErrorCode errorCode, String message, String policyRefId) { super(message); this.policyRefId = policyRefId; this.errorCode = errorCode; } private AutoScalePolicyException(ErrorCode errorCode, String message, Throwable cause) { super(message, cause); this.errorCode = errorCode; } private AutoScalePolicyException(ErrorCode errorCode, Throwable cause, String policyRefId) { super(cause); this.errorCode = errorCode; this.policyRefId = policyRefId; } public ErrorCode getErrorCode() { return errorCode; } public String getJobId() { return jobId; } public String getPolicyRefId() { return policyRefId; } public static AutoScalePolicyException errorCreatingPolicy(String policyRefId, String message) { return new AutoScalePolicyException(ErrorCode.ErrorCreatingPolicy, message, policyRefId); } public static AutoScalePolicyException errorCreatingAlarm(String policyRefId, String message) { return new AutoScalePolicyException(ErrorCode.ErrorCreatingAlarm, message, policyRefId); } public static AutoScalePolicyException errorCreatingTarget(String policyRefId, String jobId, String message) { return new AutoScalePolicyException(ErrorCode.ErrorCreatingTarget, message, policyRefId, jobId); } public static AutoScalePolicyException errorDeletingPolicy(String policyRefId, String message) { return new AutoScalePolicyException(ErrorCode.ErrorDeletingPolicy, message, policyRefId); } public static AutoScalePolicyException errorDeletingAlarm(String policyRefId, String message) { return new AutoScalePolicyException(ErrorCode.ErrorDeletingAlarm, message, policyRefId); } public static AutoScalePolicyException errorDeletingTarget(String policyRefId, String jobId, String message) { return new AutoScalePolicyException(ErrorCode.ErrorDeletingTarget, message, policyRefId, jobId); } public static AutoScalePolicyException errorUpdatingTargets(String policyRefId, String jobId, String message) { return new AutoScalePolicyException(ErrorCode.ErrorUpdatingTargets, message, policyRefId, jobId); } public static AutoScalePolicyException invalidScalingPolicy(String policyRefId, String message) { return new AutoScalePolicyException(ErrorCode.InvalidScalingPolicy, message, policyRefId); } public static AutoScalePolicyException unknownScalingPolicy(String policyRefId, String message) { return new AutoScalePolicyException(ErrorCode.UnknownScalingPolicy, message, policyRefId); } public static AutoScalePolicyException wrapJobManagerException(String policyRefId, JobManagerException jobManagerException) { return new AutoScalePolicyException(ErrorCode.JobManagerError, jobManagerException, policyRefId); } }
9,678
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/service/AppScaleManager.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.service; import com.netflix.titus.api.appscale.model.AutoScalingPolicy; import rx.Completable; import rx.Observable; public interface AppScaleManager { Observable<String> createAutoScalingPolicy(AutoScalingPolicy autoScalingPolicy); Completable updateAutoScalingPolicy(AutoScalingPolicy autoScalingPolicy); Observable<AutoScalingPolicy> getScalingPoliciesForJob(String jobId); Observable<AutoScalingPolicy> getScalingPolicy(String policyRefId); Completable removeAutoScalingPolicy(String policyRefId); Observable<AutoScalingPolicy> getAllScalingPolicies(); }
9,679
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/AppScalePolicyStore.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store; import com.netflix.titus.api.appscale.model.AutoScalingPolicy; import com.netflix.titus.api.appscale.model.PolicyStatus; import rx.Completable; import rx.Observable; public interface AppScalePolicyStore { /** * Initialize the store. */ Completable init(); /** * Retrieve all policies * * @return Observable for AutoScalingPolicy */ Observable<AutoScalingPolicy> retrievePolicies(boolean includeArchived); Observable<String> storePolicy(AutoScalingPolicy autoScalingPolicy); Completable updatePolicyId(String policyRefId, String policyId); Completable updateAlarmId(String policyRefId, String alarmId); Completable updatePolicyStatus(String policyRefId, PolicyStatus policyStatus); Completable updateStatusMessage(String policyRefId, String statusMessage); /** * Retrieve auto scaling policies for a Titus Job * * @param jobId identifies a Titus Job * @return Observable for AutoScalingPolicy */ Observable<AutoScalingPolicy> retrievePoliciesForJob(String jobId); /** * Updates policy configuration for auto scaling policy * * @param autoScalingPolicy * @return */ Completable updatePolicyConfiguration(AutoScalingPolicy autoScalingPolicy); Observable<AutoScalingPolicy> retrievePolicyForRefId(String policyRefId); Completable removePolicy(String policyRefId); }
9,680
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/StepAdjustmentMixIn.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class StepAdjustmentMixIn { @JsonCreator StepAdjustmentMixIn( @JsonProperty("scalingAdjustment") int scalingAdjustment, @JsonProperty("metricIntervalLowerBound") Optional<Double> metricIntervalLowerBound, @JsonProperty("metricIntervalUpperBound") Optional<Double> metricIntervalUpperBound) { } }
9,681
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/TargetTrackingPolicyMixin.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.netflix.titus.api.appscale.model.CustomizedMetricSpecification; import com.netflix.titus.api.appscale.model.PredefinedMetricSpecification; public class TargetTrackingPolicyMixin { @JsonCreator TargetTrackingPolicyMixin( @JsonProperty("targetValue") double targetValue, @JsonProperty("scaleOutCooldownSec") Optional<Integer> scaleOutCooldownSec, @JsonProperty("scaleInCooldownSec") Optional<Integer> scaleInCooldownSec, @JsonProperty("predefinedMetricSpecification") Optional<PredefinedMetricSpecification> predefinedMetricSpecification, @JsonProperty("disableScaleIn") Optional<Boolean> disableScaleIn, @JsonProperty("customizedMetricSpecification") Optional<CustomizedMetricSpecification> customizedMetricSpecification) { } }
9,682
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/MetricDimensionMixin.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class MetricDimensionMixin { @JsonCreator MetricDimensionMixin( @JsonProperty("name") String name, @JsonProperty("value") String value) { } }
9,683
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/CustomizedMetricSpecificationMixin.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import java.util.List; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.netflix.titus.api.appscale.model.MetricDimension; import com.netflix.titus.api.appscale.model.Statistic; public class CustomizedMetricSpecificationMixin { @JsonCreator CustomizedMetricSpecificationMixin( @JsonProperty("metricDimensionList") List<MetricDimension> metricDimensionList, @JsonProperty("metricName") String metricName, @JsonProperty("namespace") String namespace, @JsonProperty("statistic") Statistic statistic, @JsonProperty("unit") Optional<String> unit) { } }
9,684
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/PredefinedMetricSpecificationMixin.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; public class PredefinedMetricSpecificationMixin { @JsonCreator PredefinedMetricSpecificationMixin( @JsonProperty("predefinedMetricType") String predefinedMetricType, @JsonProperty("resourceLabel") Optional<String> resourceLabel) { } }
9,685
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/AlarmConfigurationMixIn.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import java.util.List; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.netflix.titus.api.appscale.model.ComparisonOperator; import com.netflix.titus.api.appscale.model.MetricDimension; import com.netflix.titus.api.appscale.model.Statistic; @JsonIgnoreProperties(ignoreUnknown = true) public abstract class AlarmConfigurationMixIn { @JsonCreator AlarmConfigurationMixIn( @JsonProperty("name") String name, @JsonProperty("region") String region, @JsonProperty("actionsEnabled") Optional<Boolean> actionsEnabled, @JsonProperty("comparisonOperator") ComparisonOperator comparisonOperator, @JsonProperty("evaluationPeriods") int evaluationPeriods, @JsonProperty("period") int period, @JsonProperty("threshold") double threshold, @JsonProperty("metricNamespace") String metricNamespace, @JsonProperty("metricName") String metricName, @JsonProperty("statistic") Statistic statistic, @JsonProperty("dimensions") List<MetricDimension> dimensions ) { } }
9,686
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/StepScalingPolicyConfigurationMixIn.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import java.util.List; import java.util.Optional; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.netflix.titus.api.appscale.model.MetricAggregationType; import com.netflix.titus.api.appscale.model.StepAdjustment; import com.netflix.titus.api.appscale.model.StepAdjustmentType; public abstract class StepScalingPolicyConfigurationMixIn { @JsonCreator StepScalingPolicyConfigurationMixIn( @JsonProperty("estimatedInstanceWarmup") Optional<Integer> coolDown, @JsonProperty("metricAggregationType") Optional<MetricAggregationType> metricAggregationType, @JsonProperty("adjustmentType") Optional<StepAdjustmentType> adjustmentType, @JsonProperty("minAdjustmentMagnitude") Optional<Long> minAdjustmentMagnitude, @JsonProperty("steps") List<StepAdjustment> steps) { } }
9,687
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/AutoScalingPolicyMixIn.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.netflix.titus.api.appscale.model.PolicyConfiguration; import com.netflix.titus.api.appscale.model.PolicyStatus; public class AutoScalingPolicyMixIn { @JsonCreator AutoScalingPolicyMixIn( @JsonProperty("refId") String refId, @JsonProperty("jobId") String jobId, @JsonProperty("policyConfiguration") PolicyConfiguration policyConfiguration, @JsonProperty("policyId") String policyId, @JsonProperty("alarmId") String alarmId, @JsonProperty("status") PolicyStatus status) { } }
9,688
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/appscale/store/mixin/PolicyConfigurationMixIn.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.appscale.store.mixin; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.netflix.titus.api.appscale.model.AlarmConfiguration; import com.netflix.titus.api.appscale.model.PolicyType; import com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration; import com.netflix.titus.api.appscale.model.TargetTrackingPolicy; public class PolicyConfigurationMixIn { @JsonCreator PolicyConfigurationMixIn( @JsonProperty("name") String name, @JsonProperty("policyType") PolicyType policyType, @JsonProperty("stepScalingPolicyConfiguration") StepScalingPolicyConfiguration stepScalingPolicyConfiguration, @JsonProperty("alarmConfiguration") AlarmConfiguration alarmConfiguration, @JsonProperty("targetTrackingPolicy") TargetTrackingPolicy targetTrackingPolicy) { } }
9,689
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/MasterState.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model; public enum MasterState { Starting, Inactive, NonLeader, LeaderActivating, LeaderActivated; public static boolean isLeader(MasterState state) { return state == MasterState.LeaderActivating || state == MasterState.LeaderActivated; } public static boolean isAfter(MasterState before, MasterState after) { return before.ordinal() < after.ordinal(); } }
9,690
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/MasterInstanceFunctions.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model; import java.util.List; import com.netflix.titus.common.util.CollectionsExt; public final class MasterInstanceFunctions { private static final int MAX_STATUS_HISTORY_SIZE = 20; private MasterInstanceFunctions() { } public static MasterInstance moveTo(MasterInstance masterInstance, MasterStatus nextStatus) { List<MasterStatus> statusHistory = CollectionsExt.copyAndAdd(masterInstance.getStatusHistory(), masterInstance.getStatus()); if (statusHistory.size() > MAX_STATUS_HISTORY_SIZE) { statusHistory = statusHistory.subList(statusHistory.size() - MAX_STATUS_HISTORY_SIZE, statusHistory.size()); } return masterInstance.toBuilder() .withStatus(nextStatus) .withStatusHistory(statusHistory) .build(); } public static boolean areDifferent(MasterInstance first, MasterInstance second) { if (first == null) { return second != null; } if (second == null) { return true; } return !clearTimestamp(first).equals(clearTimestamp(second)); } public static boolean areDifferent(MasterStatus first, MasterStatus second) { if (first == null) { return second != null; } if (second == null) { return true; } return !clearTimestamp(first).equals(clearTimestamp(second)); } public static boolean areDifferent(ReadinessStatus first, ReadinessStatus second) { if (first == null) { return second != null; } if (second == null) { return true; } return !clearTimestamp(first).equals(clearTimestamp(second)); } private static MasterInstance clearTimestamp(MasterInstance instance) { return instance.toBuilder().withStatus(instance.getStatus().toBuilder().withTimestamp(0).build()).build(); } private static MasterStatus clearTimestamp(MasterStatus status) { return status.toBuilder().withTimestamp(0).build(); } private static ReadinessStatus clearTimestamp(ReadinessStatus first) { return first.toBuilder().withTimestamp(0).build(); } }
9,691
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/ServerPort.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model; import java.util.Objects; import com.google.common.base.Preconditions; import com.netflix.titus.common.util.Evaluators; public class ServerPort { private final int portNumber; private final String protocol; private final boolean secure; private final String description; public ServerPort(int portNumber, String protocol, boolean secure, String description) { this.portNumber = portNumber; this.protocol = protocol; this.secure = secure; this.description = description; } public int getPortNumber() { return portNumber; } public String getProtocol() { return protocol; } public boolean isSecure() { return secure; } public String getDescription() { return description; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ServerPort that = (ServerPort) o; return portNumber == that.portNumber && secure == that.secure && Objects.equals(protocol, that.protocol) && Objects.equals(description, that.description); } @Override public int hashCode() { return Objects.hash(portNumber, protocol, secure, description); } @Override public String toString() { return "ServerPort{" + "portNumber=" + portNumber + ", protocol='" + protocol + '\'' + ", secure=" + secure + ", description='" + description + '\'' + '}'; } public Builder toBuilder() { return newBuilder().withPortNumber(portNumber).withProtocol(protocol).withSecure(secure).withDescription(description); } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private int portNumber; private String protocol; private boolean secure; private String description; private Builder() { } public Builder withPortNumber(int portNumber) { this.portNumber = portNumber; return this; } public Builder withProtocol(String protocol) { this.protocol = protocol; return this; } public Builder withSecure(boolean secure) { this.secure = secure; return this; } public Builder withDescription(String description) { this.description = description; return this; } public ServerPort build() { Preconditions.checkNotNull(protocol, "Protocol not set"); this.description = Evaluators.getOrDefault(description, ""); return new ServerPort(portNumber, protocol, secure, description); } } }
9,692
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/ReadinessState.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model; public enum ReadinessState { /** * Master instance not ready yet. */ NotReady, /** * Master instance not allowed to join leader election process. */ Disabled, /** * Master instance ready, and allowed to join leader election process. */ Enabled }
9,693
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/MasterInstance.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; import com.google.common.base.Preconditions; import com.netflix.titus.common.util.Evaluators; public class MasterInstance { private final String instanceId; private final String instanceGroupId; private final String ipAddress; private final MasterStatus status; private final List<MasterStatus> statusHistory; private final List<ServerPort> serverPorts; private final Map<String, String> labels; public MasterInstance(String instanceId, String instanceGroupId, String ipAddress, MasterStatus status, List<MasterStatus> statusHistory, List<ServerPort> serverPorts, Map<String, String> labels) { this.instanceId = instanceId; this.instanceGroupId = instanceGroupId; this.ipAddress = ipAddress; this.status = status; this.statusHistory = statusHistory; this.serverPorts = serverPorts; this.labels = labels; } public String getInstanceId() { return instanceId; } public String getInstanceGroupId() { return instanceGroupId; } public String getIpAddress() { return ipAddress; } public MasterStatus getStatus() { return status; } public List<MasterStatus> getStatusHistory() { return statusHistory; } public List<ServerPort> getServerPorts() { return serverPorts; } public Map<String, String> getLabels() { return labels; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MasterInstance that = (MasterInstance) o; return Objects.equals(instanceId, that.instanceId) && Objects.equals(instanceGroupId, that.instanceGroupId) && Objects.equals(ipAddress, that.ipAddress) && Objects.equals(status, that.status) && Objects.equals(statusHistory, that.statusHistory) && Objects.equals(serverPorts, that.serverPorts) && Objects.equals(labels, that.labels); } @Override public int hashCode() { return Objects.hash(instanceId, instanceGroupId, ipAddress, status, statusHistory, serverPorts, labels); } @Override public String toString() { return "MasterInstance{" + "instanceId='" + instanceId + '\'' + ", instanceGroupId='" + instanceGroupId + '\'' + ", ipAddress='" + ipAddress + '\'' + ", status=" + status + ", statusHistory=" + statusHistory + ", serverPorts=" + serverPorts + ", labels=" + labels + '}'; } public Builder toBuilder() { return newBuilder() .withInstanceId(instanceId) .withInstanceGroupId(instanceGroupId) .withIpAddress(ipAddress) .withStatus(status) .withStatusHistory(statusHistory) .withServerPorts(serverPorts) .withLabels(labels); } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private String instanceId; private String instanceGroupId; private String ipAddress; private MasterStatus status; private List<MasterStatus> statusHistory; private List<ServerPort> serverPorts; private Map<String, String> labels; private Builder() { } public Builder withInstanceId(String instanceId) { this.instanceId = instanceId; return this; } public Builder withInstanceGroupId(String instanceGroupId) { this.instanceGroupId = instanceGroupId; return this; } public Builder withIpAddress(String ipAddress) { this.ipAddress = ipAddress; return this; } public Builder withStatus(MasterStatus status) { this.status = status; return this; } public Builder withStatusHistory(List<MasterStatus> statusHistory) { this.statusHistory = statusHistory; return this; } public Builder withServerPorts(List<ServerPort> serverPorts) { this.serverPorts = serverPorts; return this; } public Builder withLabels(Map<String, String> labels) { this.labels = labels; return this; } public MasterInstance build() { Preconditions.checkNotNull(instanceId, "Instance id not set"); Preconditions.checkNotNull(instanceGroupId, "Instance group id not set"); Preconditions.checkNotNull(ipAddress, "ip address not set"); Preconditions.checkNotNull(status, "status not set"); this.statusHistory = Evaluators.getOrDefault(statusHistory, Collections.emptyList()); this.serverPorts = Evaluators.getOrDefault(serverPorts, Collections.emptyList()); this.labels = Evaluators.getOrDefault(labels, Collections.emptyMap()); return new MasterInstance(instanceId, instanceGroupId, ipAddress, status, statusHistory, serverPorts, labels); } } }
9,694
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/MasterStatus.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model; import java.util.Objects; public class MasterStatus { private final MasterState state; private final String message; private final long timestamp; public MasterStatus(MasterState state, String message, long timestamp) { this.state = state; this.message = message; this.timestamp = timestamp; } public MasterState getState() { return state; } public String getMessage() { return message; } public long getTimestamp() { return timestamp; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MasterStatus that = (MasterStatus) o; return timestamp == that.timestamp && state == that.state && Objects.equals(message, that.message); } @Override public int hashCode() { return Objects.hash(state, message, timestamp); } @Override public String toString() { return "MasterStatus{" + "state=" + state + ", message='" + message + '\'' + ", timestamp=" + timestamp + '}'; } public Builder toBuilder() { return newBuilder().withState(state).withMessage(message).withTimestamp(timestamp); } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private MasterState state; private String message; private long timestamp; private Builder() { } public Builder withState(MasterState state) { this.state = state; return this; } public Builder withMessage(String message) { this.message = message; return this; } public Builder withTimestamp(long timestamp) { this.timestamp = timestamp; return this; } public Builder but() { return newBuilder().withState(state).withMessage(message).withTimestamp(timestamp); } public MasterStatus build() { return new MasterStatus(state, message, timestamp); } } }
9,695
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/ReadinessStatus.java
/* * Copyright 2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model; import java.util.Objects; public class ReadinessStatus { private static final ReadinessStatus NOT_READY = ReadinessStatus.newBuilder() .withState(ReadinessState.NotReady) .withMessage("Not ready") .build(); private final ReadinessState state; private final String message; private final long timestamp; public ReadinessStatus(ReadinessState state, String message, long timestamp) { this.state = state; this.message = message; this.timestamp = timestamp; } public ReadinessState getState() { return state; } public String getMessage() { return message; } public long getTimestamp() { return timestamp; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ReadinessStatus that = (ReadinessStatus) o; return timestamp == that.timestamp && state == that.state && Objects.equals(message, that.message); } @Override public int hashCode() { return Objects.hash(state, message, timestamp); } @Override public String toString() { return "ReadinessStatus{" + "state=" + state + ", message='" + message + '\'' + ", timestamp=" + timestamp + '}'; } public Builder toBuilder() { return newBuilder().withState(state).withMessage(message).withTimestamp(timestamp); } public static ReadinessStatus notReadyNow(long now) { return NOT_READY.toBuilder().withTimestamp(now).build(); } public static Builder newBuilder() { return new Builder(); } public static final class Builder { private ReadinessState state; private String message; private long timestamp; private Builder() { } public Builder withState(ReadinessState state) { this.state = state; return this; } public Builder withMessage(String message) { this.message = message; return this; } public Builder withTimestamp(long timestamp) { this.timestamp = timestamp; return this; } public ReadinessStatus build() { return new ReadinessStatus(state, message, timestamp); } } }
9,696
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/event/SupervisorEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model.event; public abstract class SupervisorEvent { }
9,697
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/event/MasterInstanceUpdateEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model.event; import java.util.Objects; import com.netflix.titus.api.supervisor.model.MasterInstance; public class MasterInstanceUpdateEvent extends SupervisorEvent { private final MasterInstance masterInstance; public MasterInstanceUpdateEvent(MasterInstance masterInstance) { this.masterInstance = masterInstance; } public MasterInstance getMasterInstance() { return masterInstance; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MasterInstanceUpdateEvent that = (MasterInstanceUpdateEvent) o; return Objects.equals(masterInstance, that.masterInstance); } @Override public int hashCode() { return Objects.hash(masterInstance); } @Override public String toString() { return "MasterInstanceUpdateEvent{" + "masterInstance=" + masterInstance + "} " + super.toString(); } }
9,698
0
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model
Create_ds/titus-control-plane/titus-api/src/main/java/com/netflix/titus/api/supervisor/model/event/MasterInstanceRemovedEvent.java
/* * Copyright 2018 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.netflix.titus.api.supervisor.model.event; import java.util.Objects; import com.netflix.titus.api.supervisor.model.MasterInstance; public class MasterInstanceRemovedEvent extends SupervisorEvent { private final MasterInstance masterInstance; public MasterInstanceRemovedEvent(MasterInstance masterInstance) { this.masterInstance = masterInstance; } public MasterInstance getMasterInstance() { return masterInstance; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } MasterInstanceRemovedEvent that = (MasterInstanceRemovedEvent) o; return Objects.equals(masterInstance, that.masterInstance); } @Override public int hashCode() { return Objects.hash(masterInstance); } @Override public String toString() { return "MasterInstanceRemovedEvent{" + "masterInstance=" + masterInstance + "} " + super.toString(); } }
9,699