Skip to content

Commit d210064

Browse files
authored
Remove local port from API ID calculation (#1157)
1 parent df1af13 commit d210064

File tree

3 files changed

+150
-6
lines changed

3 files changed

+150
-6
lines changed

cli/local/api.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/cortexlabs/cortex/pkg/lib/errors"
2727
"github.com/cortexlabs/cortex/pkg/lib/files"
2828
"github.com/cortexlabs/cortex/pkg/lib/msgpack"
29+
"github.com/cortexlabs/cortex/pkg/lib/pointer"
2930
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
3031
"github.com/cortexlabs/cortex/pkg/types/spec"
3132
"github.com/cortexlabs/cortex/pkg/types/userconfig"
@@ -113,10 +114,25 @@ func writeAPISpec(apiSpec *spec.API) error {
113114
}
114115

115116
func areAPIsEqual(a1, a2 *spec.API) bool {
116-
if a1 != nil && a2 != nil {
117-
return strset.FromSlice(a1.ModelIDs()).IsEqual(strset.FromSlice(a2.ModelIDs())) && a1.ID == a2.ID && a1.Compute.Equals(a2.Compute)
117+
if a1 == nil && a2 == nil {
118+
return true
118119
}
119-
return a1 == nil && a2 == nil
120+
if a1 == nil || a2 == nil {
121+
return false
122+
}
123+
if a1.ID != a2.ID {
124+
return false
125+
}
126+
if !pointer.AreIntsEqual(a1.Networking.LocalPort, a2.Networking.LocalPort) {
127+
return false
128+
}
129+
if !a1.Compute.Equals(a2.Compute) {
130+
return false
131+
}
132+
if !strset.FromSlice(a1.ModelIDs()).IsEqual(strset.FromSlice(a2.ModelIDs())) {
133+
return false
134+
}
135+
return true
120136
}
121137

122138
func DeleteAPI(apiName string) error {

pkg/lib/pointer/equal.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
Copyright 2020 Cortex Labs, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package pointer
18+
19+
import (
20+
"time"
21+
)
22+
23+
func AreIntsEqual(v1 *int, v2 *int) bool {
24+
if v1 == nil && v2 == nil {
25+
return true
26+
}
27+
if v1 == nil || v2 == nil {
28+
return false
29+
}
30+
return *v1 == *v2
31+
}
32+
33+
func AreInt8sEqual(v1 *int8, v2 *int8) bool {
34+
if v1 == nil && v2 == nil {
35+
return true
36+
}
37+
if v1 == nil || v2 == nil {
38+
return false
39+
}
40+
return *v1 == *v2
41+
}
42+
43+
func AreInt16sEqual(v1 *int16, v2 *int16) bool {
44+
if v1 == nil && v2 == nil {
45+
return true
46+
}
47+
if v1 == nil || v2 == nil {
48+
return false
49+
}
50+
return *v1 == *v2
51+
}
52+
53+
func AreInt32sEqual(v1 *int32, v2 *int32) bool {
54+
if v1 == nil && v2 == nil {
55+
return true
56+
}
57+
if v1 == nil || v2 == nil {
58+
return false
59+
}
60+
return *v1 == *v2
61+
}
62+
63+
func AreInt64sEqual(v1 *int64, v2 *int64) bool {
64+
if v1 == nil && v2 == nil {
65+
return true
66+
}
67+
if v1 == nil || v2 == nil {
68+
return false
69+
}
70+
return *v1 == *v2
71+
}
72+
73+
func AreFloat64sEqual(v1 *float64, v2 *float64) bool {
74+
if v1 == nil && v2 == nil {
75+
return true
76+
}
77+
if v1 == nil || v2 == nil {
78+
return false
79+
}
80+
return *v1 == *v2
81+
}
82+
83+
func AreFloat32sEqual(v1 *float32, v2 *float32) bool {
84+
if v1 == nil && v2 == nil {
85+
return true
86+
}
87+
if v1 == nil || v2 == nil {
88+
return false
89+
}
90+
return *v1 == *v2
91+
}
92+
93+
func AreStringsEqual(v1 *string, v2 *string) bool {
94+
if v1 == nil && v2 == nil {
95+
return true
96+
}
97+
if v1 == nil || v2 == nil {
98+
return false
99+
}
100+
return *v1 == *v2
101+
}
102+
103+
func AreBoolsEqual(v1 *bool, v2 *bool) bool {
104+
if v1 == nil && v2 == nil {
105+
return true
106+
}
107+
if v1 == nil || v2 == nil {
108+
return false
109+
}
110+
return *v1 == *v2
111+
}
112+
113+
func AreTimesEqual(v1 *time.Time, v2 *time.Time) bool {
114+
if v1 == nil && v2 == nil {
115+
return true
116+
}
117+
if v1 == nil || v2 == nil {
118+
return false
119+
}
120+
return v1.Equal(*v2)
121+
}
122+
123+
func AreDurationsEqual(v1 *time.Duration, v2 *time.Duration) bool {
124+
if v1 == nil && v2 == nil {
125+
return true
126+
}
127+
if v1 == nil || v2 == nil {
128+
return false
129+
}
130+
return *v1 == *v2
131+
}

pkg/types/spec/api.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ type LocalModelCache struct {
5050
func GetAPISpec(apiConfig *userconfig.API, projectID string, deploymentID string) *API {
5151
var buf bytes.Buffer
5252
buf.WriteString(apiConfig.Name)
53-
if apiConfig.Networking.LocalPort != nil {
54-
buf.WriteString(s.Obj(*apiConfig.Networking.LocalPort))
55-
}
5653
buf.WriteString(s.Obj(apiConfig.Predictor))
5754
buf.WriteString(s.Obj(apiConfig.Monitoring))
5855
buf.WriteString(deploymentID)

0 commit comments

Comments
 (0)