forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ImmutableWorkerInfo instead of ZKWorker
review comments add test for equals and hashcode
- Loading branch information
1 parent
d51a0a0
commit 9cceff2
Showing
23 changed files
with
593 additions
and
284 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
indexing-service/src/main/java/io/druid/indexing/overlord/ImmutableWorkerInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Metamarkets 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 io.druid.indexing.overlord; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.ImmutableSet; | ||
import io.druid.indexing.common.task.Task; | ||
import io.druid.indexing.worker.Worker; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
/** | ||
* A snapshot of a Worker and its current state i.e tasks assigned to that worker. | ||
*/ | ||
public class ImmutableWorkerInfo | ||
{ | ||
private final Worker worker; | ||
private final int currCapacityUsed; | ||
private final ImmutableSet<String> availabilityGroups; | ||
private final ImmutableSet<String> runningTasks; | ||
private final DateTime lastCompletedTaskTime; | ||
|
||
@JsonCreator | ||
public ImmutableWorkerInfo( | ||
@JsonProperty("worker") Worker worker, | ||
@JsonProperty("currCapacityUsed") int currCapacityUsed, | ||
@JsonProperty("availabilityGroups") Set<String> availabilityGroups, | ||
@JsonProperty("runningTasks") Collection<String> runningTasks, | ||
@JsonProperty("lastCompletedTaskTime") DateTime lastCompletedTaskTime | ||
) | ||
{ | ||
this.worker = worker; | ||
this.currCapacityUsed = currCapacityUsed; | ||
this.availabilityGroups = ImmutableSet.copyOf(availabilityGroups); | ||
this.runningTasks = ImmutableSet.copyOf(runningTasks); | ||
this.lastCompletedTaskTime = lastCompletedTaskTime; | ||
} | ||
|
||
@JsonProperty("worker") | ||
public Worker getWorker() | ||
{ | ||
return worker; | ||
} | ||
|
||
@JsonProperty("currCapacityUsed") | ||
public int getCurrCapacityUsed() | ||
{ | ||
return currCapacityUsed; | ||
} | ||
|
||
@JsonProperty("availabilityGroups") | ||
public Set<String> getAvailabilityGroups() | ||
{ | ||
return availabilityGroups; | ||
} | ||
|
||
@JsonProperty("runningTasks") | ||
public Set<String> getRunningTasks() | ||
{ | ||
return runningTasks; | ||
} | ||
|
||
@JsonProperty("lastCompletedTaskTime") | ||
public DateTime getLastCompletedTaskTime() | ||
{ | ||
return lastCompletedTaskTime; | ||
} | ||
|
||
public boolean isValidVersion(String minVersion) | ||
{ | ||
return worker.getVersion().compareTo(minVersion) >= 0; | ||
} | ||
|
||
public boolean canRunTask(Task task) | ||
{ | ||
return (worker.getCapacity() - getCurrCapacityUsed() >= task.getTaskResource().getRequiredCapacity() | ||
&& !getAvailabilityGroups().contains(task.getTaskResource().getAvailabilityGroup())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
ImmutableWorkerInfo that = (ImmutableWorkerInfo) o; | ||
|
||
if (currCapacityUsed != that.currCapacityUsed) { | ||
return false; | ||
} | ||
if (!worker.equals(that.worker)) { | ||
return false; | ||
} | ||
if (!availabilityGroups.equals(that.availabilityGroups)) { | ||
return false; | ||
} | ||
if (!runningTasks.equals(that.runningTasks)) { | ||
return false; | ||
} | ||
return lastCompletedTaskTime.equals(that.lastCompletedTaskTime); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
int result = worker.hashCode(); | ||
result = 31 * result + currCapacityUsed; | ||
result = 31 * result + availabilityGroups.hashCode(); | ||
result = 31 * result + runningTasks.hashCode(); | ||
result = 31 * result + lastCompletedTaskTime.hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "ImmutableWorkerInfo{" + | ||
"worker=" + worker + | ||
", currCapacityUsed=" + currCapacityUsed + | ||
", availabilityGroups=" + availabilityGroups + | ||
", runningTasks=" + runningTasks + | ||
", lastCompletedTaskTime=" + lastCompletedTaskTime + | ||
'}'; | ||
} | ||
} |
69 changes: 0 additions & 69 deletions
69
indexing-service/src/main/java/io/druid/indexing/overlord/ImmutableZkWorker.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.