frnidito commented on a change in pull request #8987: URL: https://github.com/apache/druid/pull/8987#discussion_r411424655
########## File path: extensions-contrib/gce-extensions/src/main/java/org/apache/druid/indexing/overlord/autoscaling/gce/GceAutoScaler.java ########## @@ -0,0 +1,539 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.druid.indexing.overlord.autoscaling.gce; + +import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.services.compute.Compute; +import com.google.api.services.compute.ComputeScopes; +import com.google.api.services.compute.model.Instance; +import com.google.api.services.compute.model.InstanceGroupManagersDeleteInstancesRequest; +import com.google.api.services.compute.model.InstanceGroupManagersListManagedInstancesResponse; +import com.google.api.services.compute.model.InstanceList; +import com.google.api.services.compute.model.ManagedInstance; +import com.google.api.services.compute.model.NetworkInterface; +import com.google.api.services.compute.model.Operation; +import com.google.common.base.Preconditions; +import com.google.common.net.InetAddresses; +import org.apache.curator.shaded.com.google.common.annotations.VisibleForTesting; +import org.apache.druid.indexing.overlord.autoscaling.AutoScaler; +import org.apache.druid.indexing.overlord.autoscaling.AutoScalingData; +import org.apache.druid.indexing.overlord.autoscaling.SimpleWorkerProvisioningConfig; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.emitter.EmittingLogger; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * This module permits the autoscaling of the workers in GCE + * + * General notes: + * - The IPs are IPs as in Internet Protocol, and they look like 1.2.3.4 + * - The IDs are the names of the instances of instances created, they look like prefix-abcd, + * where the prefix is chosen by you and abcd is a suffix assigned by GCE + */ +@JsonTypeName("gce") +public class GceAutoScaler implements AutoScaler<GceEnvironmentConfig> +{ + private static final EmittingLogger log = new EmittingLogger(GceAutoScaler.class); + + private final GceEnvironmentConfig envConfig; + private final int minNumWorkers; + private final int maxNumWorkers; + private final SimpleWorkerProvisioningConfig config; // For future use + + private Compute cachedComputeService = null; + + private static final long POLL_INTERVAL_MS = 5 * 1000; // 5 sec + private static final int RUNNING_INSTANCES_MAX_RETRIES = 10; + private static final int OPERATION_END_MAX_RETRIES = 10; + + @JsonCreator + public GceAutoScaler( + @JsonProperty("minNumWorkers") int minNumWorkers, + @JsonProperty("maxNumWorkers") int maxNumWorkers, + @JsonProperty("envConfig") GceEnvironmentConfig envConfig, + @JacksonInject SimpleWorkerProvisioningConfig config + ) + { + Preconditions.checkArgument(minNumWorkers > 0, + "minNumWorkers must be greater than 0"); + this.minNumWorkers = minNumWorkers; + Preconditions.checkArgument(maxNumWorkers > 0, + "maxNumWorkers must be greater than 0"); + Preconditions.checkArgument(maxNumWorkers > minNumWorkers, + "maxNumWorkers must be greater than minNumWorkers"); + this.maxNumWorkers = maxNumWorkers; + this.envConfig = envConfig; + this.config = config; + } + + /** + * CAVEAT: this is meant to be used only for testing passing a mock version of Compute + */ + @VisibleForTesting + public GceAutoScaler( + int minNumWorkers, + int maxNumWorkers, + GceEnvironmentConfig envConfig, + SimpleWorkerProvisioningConfig config, + Compute compute + ) + { + this(minNumWorkers, maxNumWorkers, envConfig, config); + this.cachedComputeService = compute; + } + + @Override + @JsonProperty + public int getMinNumWorkers() + { + return minNumWorkers; + } + + @Override + @JsonProperty + public int getMaxNumWorkers() + { + return maxNumWorkers; + } + + @Override + @JsonProperty + public GceEnvironmentConfig getEnvConfig() + { + return envConfig; + } + + private synchronized Compute createComputeService() Review comment: done ########## File path: extensions-contrib/gce-extensions/src/main/java/org/apache/druid/indexing/overlord/autoscaling/gce/GceAutoScaler.java ########## @@ -0,0 +1,539 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.druid.indexing.overlord.autoscaling.gce; + +import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.services.compute.Compute; +import com.google.api.services.compute.ComputeScopes; +import com.google.api.services.compute.model.Instance; +import com.google.api.services.compute.model.InstanceGroupManagersDeleteInstancesRequest; +import com.google.api.services.compute.model.InstanceGroupManagersListManagedInstancesResponse; +import com.google.api.services.compute.model.InstanceList; +import com.google.api.services.compute.model.ManagedInstance; +import com.google.api.services.compute.model.NetworkInterface; +import com.google.api.services.compute.model.Operation; +import com.google.common.base.Preconditions; +import com.google.common.net.InetAddresses; +import org.apache.curator.shaded.com.google.common.annotations.VisibleForTesting; +import org.apache.druid.indexing.overlord.autoscaling.AutoScaler; +import org.apache.druid.indexing.overlord.autoscaling.AutoScalingData; +import org.apache.druid.indexing.overlord.autoscaling.SimpleWorkerProvisioningConfig; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.emitter.EmittingLogger; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * This module permits the autoscaling of the workers in GCE + * + * General notes: + * - The IPs are IPs as in Internet Protocol, and they look like 1.2.3.4 + * - The IDs are the names of the instances of instances created, they look like prefix-abcd, + * where the prefix is chosen by you and abcd is a suffix assigned by GCE + */ +@JsonTypeName("gce") +public class GceAutoScaler implements AutoScaler<GceEnvironmentConfig> +{ + private static final EmittingLogger log = new EmittingLogger(GceAutoScaler.class); + + private final GceEnvironmentConfig envConfig; + private final int minNumWorkers; + private final int maxNumWorkers; + private final SimpleWorkerProvisioningConfig config; // For future use Review comment: done ########## File path: extensions-contrib/gce-extensions/src/main/java/org/apache/druid/indexing/overlord/autoscaling/gce/GceEnvironmentConfig.java ########## @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.druid.indexing.overlord.autoscaling.gce; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Preconditions; + +import java.util.Objects; + +/** + */ +public class GceEnvironmentConfig +{ + /** + * numInstances: the number of workers to try to spawn at each call to provision + * projectId: the id of the project where to operate + * zoneName: the name of the zone where to operata + * instanceTemplate: the template to use when creating the instances + * minworkers: the minimum number of workers in the pool (*) + * maxWorkers: the maximum number of workers in the pool (*) + * + * (*) both used by the caller of the AutoScaler to know if it makes sense to call + * provision / terminate or if there is no hope that something would be done + */ + private final int numInstances; + private final String projectId; + private final String zoneName; + private final String managedInstanceGroupName; + + @JsonCreator + public GceEnvironmentConfig( + @JsonProperty("numInstances") int numInstances, + @JsonProperty("projectId") String projectId, + @JsonProperty("zoneName") String zoneName, + @JsonProperty("managedInstanceGroupName") String managedInstanceGroupName + ) + { + Preconditions.checkArgument(numInstances > 0, + "numInstances must be greater than 0"); + this.numInstances = numInstances; + this.projectId = Preconditions.checkNotNull(projectId, + "projectId must be not null"); + this.zoneName = Preconditions.checkNotNull(zoneName, + "zoneName nust be not null"); + this.managedInstanceGroupName = Preconditions.checkNotNull( + managedInstanceGroupName, + "managedInstanceGroupName must be not null" + ); + } + + @JsonProperty + public int getNumInstances() + { + return numInstances; + } + + + @JsonProperty + String getZoneName() + { + return zoneName; + } + + @JsonProperty + String getProjectId() + { + return projectId; + } + + @JsonProperty + String getManagedInstanceGroupName() + { + return managedInstanceGroupName; + } + + @Override + public String toString() + { + return "GceEnvironmentConfig={" + + "projectId=" + projectId + + ", zoneName=" + zoneName + + ", numInstances=" + numInstances + + ", managedInstanceGroupName=" + managedInstanceGroupName + + '}'; + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + GceEnvironmentConfig that = (GceEnvironmentConfig) o; + return (numInstances == that.numInstances && + projectId.equals(that.projectId) && + zoneName.equals(that.zoneName) && + managedInstanceGroupName.equals(that.managedInstanceGroupName)); + } + + @Override + public int hashCode() + { + int result = 0; + result = 31 * result + Objects.hashCode(projectId); + result = 31 * result + Objects.hashCode(zoneName); + result = 31 * result + Objects.hashCode(managedInstanceGroupName); + result = 31 * result + numInstances; + return result; + } Review comment: done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
