You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2018/07/09 20:59:15 UTC
helix git commit: [HELIX-715] Add NOP classes for quota management
support
Repository: helix
Updated Branches:
refs/heads/master 3870ab0f3 -> ebbd6ba2e
[HELIX-715] Add NOP classes for quota management support
The following classes and interfaces were added: TaskAssigner, AssignableInstance, and TaskAssignResult.
Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/ebbd6ba2
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/ebbd6ba2
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/ebbd6ba2
Branch: refs/heads/master
Commit: ebbd6ba2ed57e75e5fe3506aa6fcd9f5938330fd
Parents: 3870ab0
Author: Hunter Lee <na...@gmail.com>
Authored: Mon Jul 9 12:28:39 2018 -0700
Committer: Hunter Lee <na...@gmail.com>
Committed: Mon Jul 9 13:58:49 2018 -0700
----------------------------------------------------------------------
.../helix/task/assigner/AssignableInstance.java | 99 ++++++++++++++++++++
.../helix/task/assigner/TaskAssignResult.java | 69 ++++++++++++++
.../helix/task/assigner/TaskAssigner.java | 37 ++++++++
3 files changed, 205 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/helix/blob/ebbd6ba2/helix-core/src/main/java/org/apache/helix/task/assigner/AssignableInstance.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/assigner/AssignableInstance.java b/helix-core/src/main/java/org/apache/helix/task/assigner/AssignableInstance.java
new file mode 100644
index 0000000..fe59275
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/task/assigner/AssignableInstance.java
@@ -0,0 +1,99 @@
+package org.apache.helix.task.assigner;
+
+/*
+ * 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.
+ */
+
+import java.util.Map;
+import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.task.TaskConfig;
+
+/**
+ * AssignableInstance contains instance capacity profile and methods that control capacity and help
+ * with task assignment.
+ */
+public class AssignableInstance {
+
+ /**
+ * Caches tasks currently assigned to this instance.
+ * Every pipeline iteration will compare Task states in this map to Task states in TaskDataCache.
+ * Tasks in a terminal state (finished or failed) will be removed as soon as they reach the state.
+ */
+ private Map<String, TaskAssignResult> _currentAssignments;
+ private ClusterConfig _clusterConfig;
+ private InstanceConfig _instanceConfig;
+ private LiveInstance _liveInstance;
+
+ public AssignableInstance(ClusterConfig clusterConfig, InstanceConfig instanceConfig,
+ LiveInstance liveInstance) {
+ _clusterConfig = clusterConfig;
+ _instanceConfig = instanceConfig;
+ _liveInstance = liveInstance;
+ }
+
+ /**
+ * Tries to assign the given task on this instance and returns TaskAssignResult. Instance capacity
+ * profile is NOT modified by tryAssign.
+ * @param task
+ * @return
+ */
+ public TaskAssignResult tryAssign(TaskConfig task) {
+ // TODO: implement
+ return null;
+ }
+
+ /**
+ * Performs the following to accept a task:
+ * 1. Deduct the amount of resource required by this task
+ * 2. Add this TaskAssignResult to _currentAssignments
+ * @param result
+ * @throws IllegalStateException if TaskAssignResult is not successful
+ */
+ public void assign(TaskAssignResult result) throws IllegalStateException {
+ // TODO: implement
+ return;
+ }
+
+ /**
+ * Performs the following to release resource for a task:
+ * 1. Release the resource by adding back what the task required.
+ * 2. Remove the TaskAssignResult from _currentAssignments
+ * @param taskID
+ * @throws IllegalArgumentException if task is not found
+ */
+ public void release(String taskID) throws IllegalArgumentException {
+ // TODO: implement
+ return;
+ }
+
+ /**
+ * Returns taskID -> TaskAssignResult mappings.
+ */
+ public Map<String, TaskAssignResult> getCurrentAssignments() {
+ return _currentAssignments;
+ }
+
+ /**
+ * Returns the name of this instance.
+ */
+ public String getInstanceName() {
+ return _instanceConfig.getInstanceName();
+ }
+}
http://git-wip-us.apache.org/repos/asf/helix/blob/ebbd6ba2/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssignResult.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssignResult.java b/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssignResult.java
new file mode 100644
index 0000000..3515cbb
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssignResult.java
@@ -0,0 +1,69 @@
+package org.apache.helix.task.assigner;
+
+/*
+ * 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.
+ */
+
+import org.apache.helix.task.TaskConfig;
+
+/**
+ * TaskAssignResult represents assignment metadata for a task and is created by TaskAssigner.
+ */
+public class TaskAssignResult {
+
+ public enum FailureReason {
+ // Instance does not have sufficient resource quota
+ INSUFFICIENT_QUOTA
+ }
+
+ private boolean isAssignmentSuccessful;
+
+ /**
+ * Returns if the task is successfully assigned or not.
+ * @return true if assignment was successful. False otherwise
+ */
+ public boolean isSuccessful() {
+ return isAssignmentSuccessful;
+ }
+
+ /**
+ * Returns TaskConfig of this TaskAssignResult.
+ */
+ public TaskConfig getTaskConfig() {
+ // TODO: implement
+ return new TaskConfig(null, null);
+ }
+
+ /**
+ * Returns the name of the instance this task was assigned to.
+ * @return instance name. Null if assignment was not successful
+ */
+ public String getInstanceName() {
+ // TODO: implement
+ return null;
+ }
+
+ /**
+ * Returns the reason for assignment failure.
+ * @return a FailureReason instance. Null if assignment was successful
+ */
+ public FailureReason getFailureReason() {
+ // TODO: implement
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/helix/blob/ebbd6ba2/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssigner.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssigner.java b/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssigner.java
new file mode 100644
index 0000000..66614a2
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/task/assigner/TaskAssigner.java
@@ -0,0 +1,37 @@
+package org.apache.helix.task.assigner;
+
+/*
+ * 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.
+ */
+
+import java.util.Map;
+import org.apache.helix.task.TaskConfig;
+
+public interface TaskAssigner {
+
+ /**
+ * Assign a collection of tasks on a collection of assignableInstances.
+ * When an assignment decision is made, AssignableInstance.assign() must be called for the
+ * instance to modify its internal capacity profile.
+ * @param assignableInstances
+ * @param tasks
+ * @return taskID -> TaskAssignmentResult mapping per task
+ */
+ Map<String, TaskAssignResult> assignTasks(Iterable<AssignableInstance> assignableInstances,
+ Iterable<TaskConfig> tasks);
+}