[GitHub] [incubator-yunikorn-k8shim] wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not properly released when they are removed from pending state

2020-03-25 Thread GitBox
wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not 
properly released when they are removed from pending state
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/87#discussion_r397884399
 
 

 ##
 File path: pkg/common/resource_test.go
 ##
 @@ -243,3 +243,27 @@ func TestNodeResource(t *testing.T) {
 
assert.Equal(t, result.Resources[CPU].GetValue(), int64(14500))
 }
+
+func TestCreateReleaseAllocationRequest(t *testing.T) {
+   request := CreateReleaseAllocationRequestForTask("app01", "alloc01", 
"default")
+   assert.Assert(t, request.Releases != nil)
+   assert.Assert(t, request.Releases.AllocationsToRelease != nil)
+   assert.Assert(t, request.Releases.AllocationAsksToRelease == nil)
+   assert.Equal(t, len(request.Releases.AllocationsToRelease), 1)
+   assert.Equal(t, len(request.Releases.AllocationAsksToRelease), 0)
+   assert.Equal(t, request.Releases.AllocationsToRelease[0].ApplicationID, 
"app01")
+   assert.Equal(t, request.Releases.AllocationsToRelease[0].UUID, 
"alloc01")
+   assert.Equal(t, request.Releases.AllocationsToRelease[0].PartitionName, 
"default")
+}
+
+func TestCreateReleaseAskRequestForTask(t *testing.T) {
+   request := CreateReleaseAskRequestForTask("app01", "task01", "default")
+   assert.Assert(t, request.Releases != nil)
+   assert.Assert(t, request.Releases.AllocationsToRelease == nil)
+   assert.Assert(t, request.Releases.AllocationAsksToRelease != nil)
+   assert.Equal(t, len(request.Releases.AllocationsToRelease), 0)
+   assert.Equal(t, len(request.Releases.AllocationAsksToRelease), 1)
+   assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].ApplicationID, "app01")
+   assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].Allocationkey, "task01")
+   assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].PartitionName, "default")
+}
 
 Review comment:
   missing newline at the end of the file, please add


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: dev-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: dev-h...@yunikorn.apache.org



[GitHub] [incubator-yunikorn-k8shim] wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not properly released when they are removed from pending state

2020-03-25 Thread GitBox
wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not 
properly released when they are removed from pending state
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/87#discussion_r397884399
 
 

 ##
 File path: pkg/common/resource_test.go
 ##
 @@ -243,3 +243,27 @@ func TestNodeResource(t *testing.T) {
 
assert.Equal(t, result.Resources[CPU].GetValue(), int64(14500))
 }
+
+func TestCreateReleaseAllocationRequest(t *testing.T) {
+   request := CreateReleaseAllocationRequestForTask("app01", "alloc01", 
"default")
+   assert.Assert(t, request.Releases != nil)
+   assert.Assert(t, request.Releases.AllocationsToRelease != nil)
+   assert.Assert(t, request.Releases.AllocationAsksToRelease == nil)
+   assert.Equal(t, len(request.Releases.AllocationsToRelease), 1)
+   assert.Equal(t, len(request.Releases.AllocationAsksToRelease), 0)
+   assert.Equal(t, request.Releases.AllocationsToRelease[0].ApplicationID, 
"app01")
+   assert.Equal(t, request.Releases.AllocationsToRelease[0].UUID, 
"alloc01")
+   assert.Equal(t, request.Releases.AllocationsToRelease[0].PartitionName, 
"default")
+}
+
+func TestCreateReleaseAskRequestForTask(t *testing.T) {
+   request := CreateReleaseAskRequestForTask("app01", "task01", "default")
+   assert.Assert(t, request.Releases != nil)
+   assert.Assert(t, request.Releases.AllocationsToRelease == nil)
+   assert.Assert(t, request.Releases.AllocationAsksToRelease != nil)
+   assert.Equal(t, len(request.Releases.AllocationsToRelease), 0)
+   assert.Equal(t, len(request.Releases.AllocationAsksToRelease), 1)
+   assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].ApplicationID, "app01")
+   assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].Allocationkey, "task01")
+   assert.Equal(t, 
request.Releases.AllocationAsksToRelease[0].PartitionName, "default")
+}
 
 Review comment:
   missing newline, please add


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: dev-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: dev-h...@yunikorn.apache.org



[GitHub] [incubator-yunikorn-k8shim] wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not properly released when they are removed from pending state

2020-03-25 Thread GitBox
wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not 
properly released when they are removed from pending state
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/87#discussion_r397880875
 
 

 ##
 File path: pkg/cache/task_test.go
 ##
 @@ -0,0 +1,301 @@
+/*
+ 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 cache
+
+import (
+   "testing"
+
+   "github.com/apache/incubator-yunikorn-k8shim/pkg/client"
+   "github.com/apache/incubator-yunikorn-k8shim/pkg/common/events"
+   "github.com/apache/incubator-yunikorn-scheduler-interface/lib/go/si"
+   "gotest.tools/assert"
+   v1 "k8s.io/api/core/v1"
+   "k8s.io/apimachinery/pkg/api/resource"
+   apis "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+func TestTaskStateTransitions(t *testing.T) {
+   mockedSchedulerApi := newMockSchedulerAPI()
+   mockedContext := initContextForTest()
+   resources := make(map[v1.ResourceName]resource.Quantity)
+   containers := make([]v1.Container, 0)
+   containers = append(containers, v1.Container{
+   Name: "container-01",
+   Resources: v1.ResourceRequirements{
+   Requests: resources,
+   },
+   })
+   pod := &v1.Pod{
+   TypeMeta: apis.TypeMeta{
+   Kind:   "Pod",
+   APIVersion: "v1",
+   },
+   ObjectMeta: apis.ObjectMeta{
+   Name: "pod-resource-test-1",
+   UID:  "UID-1",
+   },
+   Spec: v1.PodSpec{
+   Containers: containers,
+   },
+   }
+
+   app := NewApplication("app01", "root.default",
+   "bob", map[string]string{}, mockedSchedulerApi)
+   task := NewTask("task01", app, mockedContext, pod)
+   assert.Equal(t, task.GetTaskState(), events.States().Task.New)
+
+   // new task
+   event0 := NewSimpleTaskEvent(task.applicationID, task.taskID, 
events.InitTask)
+   if err := task.handle(event0); err != nil {
+   t.Fatal(err)
+   }
 
 Review comment:
   please use `assert.NilError` make the code easier to read


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: dev-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: dev-h...@yunikorn.apache.org



[GitHub] [incubator-yunikorn-k8shim] wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not properly released when they are removed from pending state

2020-03-25 Thread GitBox
wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not 
properly released when they are removed from pending state
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/87#discussion_r397880934
 
 

 ##
 File path: pkg/cache/task_test.go
 ##
 @@ -0,0 +1,301 @@
+/*
+ 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 cache
+
+import (
+   "testing"
+
+   "github.com/apache/incubator-yunikorn-k8shim/pkg/client"
+   "github.com/apache/incubator-yunikorn-k8shim/pkg/common/events"
+   "github.com/apache/incubator-yunikorn-scheduler-interface/lib/go/si"
+   "gotest.tools/assert"
+   v1 "k8s.io/api/core/v1"
+   "k8s.io/apimachinery/pkg/api/resource"
+   apis "k8s.io/apimachinery/pkg/apis/meta/v1"
 
 Review comment:
   please fix grouping: golang, other followed by project


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: dev-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: dev-h...@yunikorn.apache.org



[GitHub] [incubator-yunikorn-k8shim] wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not properly released when they are removed from pending state

2020-03-25 Thread GitBox
wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not 
properly released when they are removed from pending state
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/87#discussion_r397883743
 
 

 ##
 File path: pkg/client/apifactory_mock.go
 ##
 @@ -19,6 +19,7 @@
 package client
 
 import (
+   "github.com/apache/incubator-yunikorn-scheduler-interface/lib/go/si"
 
 Review comment:
   import ordering check


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: dev-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: dev-h...@yunikorn.apache.org



[GitHub] [incubator-yunikorn-k8shim] wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not properly released when they are removed from pending state

2020-03-25 Thread GitBox
wilfred-s commented on a change in pull request #87: [YUNIKORN-45] Task is not 
properly released when they are removed from pending state
URL: 
https://github.com/apache/incubator-yunikorn-k8shim/pull/87#discussion_r397883169
 
 

 ##
 File path: pkg/cache/task_test.go
 ##
 @@ -0,0 +1,301 @@
+/*
+ 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 cache
+
+import (
+   "testing"
+
+   "github.com/apache/incubator-yunikorn-k8shim/pkg/client"
+   "github.com/apache/incubator-yunikorn-k8shim/pkg/common/events"
+   "github.com/apache/incubator-yunikorn-scheduler-interface/lib/go/si"
+   "gotest.tools/assert"
+   v1 "k8s.io/api/core/v1"
+   "k8s.io/apimachinery/pkg/api/resource"
+   apis "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+func TestTaskStateTransitions(t *testing.T) {
+   mockedSchedulerApi := newMockSchedulerAPI()
+   mockedContext := initContextForTest()
+   resources := make(map[v1.ResourceName]resource.Quantity)
+   containers := make([]v1.Container, 0)
+   containers = append(containers, v1.Container{
+   Name: "container-01",
+   Resources: v1.ResourceRequirements{
+   Requests: resources,
+   },
+   })
+   pod := &v1.Pod{
+   TypeMeta: apis.TypeMeta{
+   Kind:   "Pod",
+   APIVersion: "v1",
+   },
+   ObjectMeta: apis.ObjectMeta{
+   Name: "pod-resource-test-1",
+   UID:  "UID-1",
+   },
+   Spec: v1.PodSpec{
+   Containers: containers,
+   },
+   }
+
+   app := NewApplication("app01", "root.default",
+   "bob", map[string]string{}, mockedSchedulerApi)
+   task := NewTask("task01", app, mockedContext, pod)
+   assert.Equal(t, task.GetTaskState(), events.States().Task.New)
+
+   // new task
+   event0 := NewSimpleTaskEvent(task.applicationID, task.taskID, 
events.InitTask)
+   if err := task.handle(event0); err != nil {
+   t.Fatal(err)
+   }
+   assert.Equal(t, task.GetTaskState(), events.States().Task.Pending)
+
+   // submit task to the scheduler-core
+   event1 := NewSubmitTaskEvent(app.applicationID, task.taskID)
+   if err := task.handle(event1); err != nil {
+   t.Fatal(err)
+   }
+   assert.Equal(t, task.GetTaskState(), events.States().Task.Scheduling)
+
+   // allocated
+   event2 := NewAllocateTaskEvent(app.applicationID, task.taskID, 
string(pod.UID), "node-1")
+   if err := task.handle(event2); err != nil {
+   t.Fatal(err)
+   }
+   assert.Equal(t, task.GetTaskState(), events.States().Task.Allocated)
+
+   // bound
+   event3 := NewBindTaskEvent(app.applicationID, task.taskID)
+   if err := task.handle(event3); err != nil {
+   t.Fatal(err)
+   }
+   assert.Equal(t, task.GetTaskState(), events.States().Task.Bound)
+
+   // complete
+   event4 := NewSimpleTaskEvent(app.applicationID, task.taskID, 
events.CompleteTask)
+   if err := task.handle(event4); err != nil {
+   t.Fatal(err)
+   }
+   assert.Equal(t, task.GetTaskState(), events.States().Task.Completed)
+}
+
+func TestTaskIllegalEventHandling(t *testing.T) {
+   mockedSchedulerApi := newMockSchedulerAPI()
+   mockedContext := initContextForTest()
+   resources := make(map[v1.ResourceName]resource.Quantity)
+   containers := make([]v1.Container, 0)
+   containers = append(containers, v1.Container{
+   Name: "container-01",
+   Resources: v1.ResourceRequirements{
+   Requests: resources,
+   },
+   })
+   pod := &v1.Pod{
+   TypeMeta: apis.TypeMeta{
+   Kind:   "Pod",
+   APIVersion: "v1",
+   },
+   ObjectMeta: apis.ObjectMeta{
+   Name: "pod-resource-test-1",
+   UID:  "UID-1",
+   },
+   Spec: v1.PodSpec{
+   Containers: containers,
+   }