Skip to content

Commit

Permalink
fix: service tasks filter
Browse files Browse the repository at this point in the history
Closes DCOS-41313
  • Loading branch information
nLight committed Apr 10, 2019
1 parent 533005b commit afe59df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
3 changes: 1 addition & 2 deletions plugins/services/src/js/structs/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module.exports = class Service extends Item {
return this.getId()
.split("/")
.slice(1)
.reverse()
.join(".");
.join("_");
}

getName() {
Expand Down
4 changes: 2 additions & 2 deletions plugins/services/src/js/structs/__tests__/Service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ describe("Service", function() {
});

describe("#getMesosId", function() {
it("returns correct id", function() {
it("returns correct id prefix", function() {
const service = new Service({
id: "/test/cmd"
});

expect(service.getMesosId()).toEqual("cmd.test");
expect(service.getMesosId()).toEqual("test_cmd");
});
});

Expand Down
12 changes: 8 additions & 4 deletions src/js/stores/MesosStateStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ class MesosStateStore extends GetSetBaseStore {
const { frameworks, tasks = [] } = this.getLastMesosState();
const serviceName = service.getName();

// Convert serviceId to Mesos task name
const mesosTaskName = service.getMesosId();
// Convert serviceId to Mesos task id prefix
const taskIdPrefix = service.getMesosId();

if (!serviceName || !mesosTaskName || !frameworks) {
if (!serviceName || !taskIdPrefix || !frameworks) {
return [];
}

Expand All @@ -273,7 +273,11 @@ class MesosStateStore extends GetSetBaseStore {
}

return tasks
.filter(task => task.isStartedByMarathon && task.name === mesosTaskName)
.filter(
task =>
task.isStartedByMarathon &&
task.id.startsWith(`${taskIdPrefix}.instance`)
)
.concat(serviceTasks)
.map(task => MesosStateUtil.flagSDKTask(task, service));
}
Expand Down
24 changes: 15 additions & 9 deletions src/js/stores/__tests__/MesosStateStore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,31 @@ describe("MesosStateStore", function() {
tasks: [
{
name: "spark",
id: "spark.1",
id: "spark.instance.1",
framework_id: "marathon_1",
isStartedByMarathon: true
},
{
name: "alpha",
id: "alpha.1",
id: "alpha.instance.1",
framework_id: "marathon_1",
isStartedByMarathon: true
},
{
name: "alpha",
id: "alpha.2",
id: "alpha.instance.2",
framework_id: "marathon_1",
isStartedByMarathon: true
},
{
name: "alpha",
id: "alpha.3",
id: "alpha.instance.3",
framework_id: "marathon_1",
isStartedByMarathon: true
},
{
name: "alpha",
id: "pod_alpha.instance.3",
framework_id: "marathon_1",
isStartedByMarathon: true
},
Expand All @@ -164,7 +170,7 @@ describe("MesosStateStore", function() {
expect(tasks).toEqual([
{
name: "spark",
id: "spark.1",
id: "spark.instance.1",
framework_id: "marathon_1",
isStartedByMarathon: true
},
Expand All @@ -181,19 +187,19 @@ describe("MesosStateStore", function() {
expect(tasks).toEqual([
{
name: "alpha",
id: "alpha.1",
id: "alpha.instance.1",
framework_id: "marathon_1",
isStartedByMarathon: true
},
{
name: "alpha",
id: "alpha.2",
id: "alpha.instance.2",
framework_id: "marathon_1",
isStartedByMarathon: true
},
{
name: "alpha",
id: "alpha.3",
id: "alpha.instance.3",
framework_id: "marathon_1",
isStartedByMarathon: true
}
Expand Down Expand Up @@ -239,7 +245,7 @@ describe("MesosStateStore", function() {
expect(tasks).toEqual([
{
name: "spark",
id: "spark.1",
id: "spark.instance.1",
framework_id: "marathon_1",
isStartedByMarathon: true,
sdkTask: true
Expand Down

0 comments on commit afe59df

Please sign in to comment.