Skip to content

Commit

Permalink
load instance resource兼容性适配 (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
taoran1250 authored Jan 10, 2025
1 parent 33869bd commit 84f9e32
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,51 @@ public class LoadInstanceResource extends Resource {
private final long memory;
private final int cores;
private final int instances;
// 兼容性适配
private final int instance;

private LoadInstanceResource(Resource r) {
if (r instanceof LoadInstanceResource) {
LoadInstanceResource t = (LoadInstanceResource) r;
this.memory = t.memory;
this.cores = t.cores;
this.instances = t.instances;
this.instance = t.instances;
} else if (r instanceof LoadResource) {
LoadResource l = (LoadResource) r;
this.memory = l.getMemory();
this.cores = l.getCores();
this.instances = 0;
this.instance = 0;
} else if (r instanceof MemoryResource) {
MemoryResource m = (MemoryResource) r;
this.memory = m.getMemory();
this.cores = 0;
this.instances = 0;
this.instance = 0;
} else if (r instanceof CPUResource) {
CPUResource c = (CPUResource) r;
this.memory = 0;
this.cores = c.getCores();
this.instances = 0;
this.instance = 0;
} else if (r instanceof DriverAndYarnResource) {
DriverAndYarnResource d = (DriverAndYarnResource) r;
this.memory = d.getLoadInstanceResource().getMemory();
this.cores = d.getLoadInstanceResource().getCores();
this.instances = d.getLoadInstanceResource().getInstances();
this.instance = d.getLoadInstanceResource().getInstances();
} else if (r instanceof DriverAndKubernetesResource) {
DriverAndKubernetesResource d = (DriverAndKubernetesResource) r;
this.memory = d.getLoadInstanceResource().getMemory();
this.cores = d.getLoadInstanceResource().getCores();
this.instances = d.getLoadInstanceResource().getInstances();
this.instance = d.getLoadInstanceResource().getInstances();
} else {
this.memory = Long.MAX_VALUE;
this.cores = Integer.MAX_VALUE;
this.instances = Integer.MAX_VALUE;
this.instance = Integer.MAX_VALUE;
}
}

Expand All @@ -73,6 +82,7 @@ public LoadInstanceResource(long memory, int cores, int instances) {
this.memory = memory;
this.cores = cores;
this.instances = instances;
this.instance = instances;
}

public LoadInstanceResource add(Resource r) {
Expand Down Expand Up @@ -184,4 +194,8 @@ public int getCores() {
public int getInstances() {
return instances;
}

public int getInstance() {
return instances;
}
}

0 comments on commit 84f9e32

Please sign in to comment.