Skip to content

Commit 66d5ebc

Browse files
author
Alena Prokharchyk
committed
CLOUDSTACK-6596: UUID and display flag update support for LBStickinessPolicy and LBHealthCheckPolicy
1 parent 25ab05a commit 66d5ebc

22 files changed

Lines changed: 408 additions & 32 deletions

api/src/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ public class EventTypes {
134134
public static final String EVENT_LOAD_BALANCER_CREATE = "LB.CREATE";
135135
public static final String EVENT_LOAD_BALANCER_DELETE = "LB.DELETE";
136136
public static final String EVENT_LB_STICKINESSPOLICY_CREATE = "LB.STICKINESSPOLICY.CREATE";
137+
public static final String EVENT_LB_STICKINESSPOLICY_UPDATE = "LB.STICKINESSPOLICY.UPDATE";
137138
public static final String EVENT_LB_STICKINESSPOLICY_DELETE = "LB.STICKINESSPOLICY.DELETE";
138139
public static final String EVENT_LB_HEALTHCHECKPOLICY_CREATE = "LB.HEALTHCHECKPOLICY.CREATE";
139140
public static final String EVENT_LB_HEALTHCHECKPOLICY_DELETE = "LB.HEALTHCHECKPOLICY.DELETE";
141+
public static final String EVENT_LB_HEALTHCHECKPOLICY_UPDATE = "LB.HEALTHCHECKPOLICY.UPDATE";
140142
public static final String EVENT_LOAD_BALANCER_UPDATE = "LB.UPDATE";
141143
public static final String EVENT_LB_CERT_UPLOAD = "LB.CERT.UPLOAD";
142144
public static final String EVENT_LB_CERT_DELETE = "LB.CERT.DELETE";

api/src/com/cloud/network/lb/LoadBalancingRulesService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,8 @@ LoadBalancer createPublicLoadBalancerRule(String xId, String name, String descri
155155
boolean isLbRuleMappedToVmGuestIp(String vmSecondaryIp);
156156

157157
List<String> listLbVmIpAddress(long id, long vmId);
158+
159+
StickinessPolicy updateLBStickinessPolicy(long id, String customId, Boolean forDisplay);
160+
161+
HealthCheckPolicy updateLBHealthCheckPolicy(long id, String customId, Boolean forDisplay);
158162
}

api/src/com/cloud/network/rules/HealthCheckPolicy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public interface HealthCheckPolicy extends InternalIdentity, Identity {
3939

4040
public boolean isRevoke();
4141

42+
/**
43+
* @return
44+
*/
45+
boolean isDisplay();
46+
4247
}

api/src/com/cloud/network/rules/StickinessPolicy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public interface StickinessPolicy extends InternalIdentity, Identity {
3939

4040
public List<Pair<String, String>> getParams(); /* get params in Map <string,String> format */
4141

42+
/**
43+
* @return
44+
*/
45+
boolean isDisplay();
46+
4247
}

api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.loadbalancer;
1818

19-
import org.apache.log4j.Logger;
20-
19+
import org.apache.cloudstack.acl.RoleType;
2120
import org.apache.cloudstack.api.APICommand;
2221
import org.apache.cloudstack.api.ApiConstants;
2322
import org.apache.cloudstack.api.ApiErrorCode;
@@ -27,6 +26,7 @@
2726
import org.apache.cloudstack.api.response.FirewallRuleResponse;
2827
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
2928
import org.apache.cloudstack.context.CallContext;
29+
import org.apache.log4j.Logger;
3030

3131
import com.cloud.event.EventTypes;
3232
import com.cloud.exception.InvalidParameterValueException;
@@ -89,10 +89,18 @@ public class CreateLBHealthCheckPolicyCmd extends BaseAsyncCreateCmd {
8989
description = "Number of consecutive health check failures before declaring an instance unhealthy")
9090
private int unhealthyThreshold;
9191

92+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
93+
private Boolean display;
94+
95+
9296
// ///////////////////////////////////////////////////
9397
// ///////////////// Accessors ///////////////////////
9498
// ///////////////////////////////////////////////////
9599

100+
public Boolean getDisplay() {
101+
return display;
102+
}
103+
96104
public Long getLbRuleId() {
97105
return lbRuleId;
98106
}

api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
import java.util.Map;
2020

21-
import org.apache.log4j.Logger;
22-
21+
import org.apache.cloudstack.acl.RoleType;
2322
import org.apache.cloudstack.api.APICommand;
2423
import org.apache.cloudstack.api.ApiConstants;
2524
import org.apache.cloudstack.api.ApiErrorCode;
@@ -30,6 +29,7 @@
3029
import org.apache.cloudstack.api.response.FirewallRuleResponse;
3130
import org.apache.cloudstack.api.response.LBStickinessResponse;
3231
import org.apache.cloudstack.context.CallContext;
32+
import org.apache.log4j.Logger;
3333

3434
import com.cloud.event.EventTypes;
3535
import com.cloud.exception.InvalidParameterValueException;
@@ -74,10 +74,18 @@ public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd {
7474
@Parameter(name = ApiConstants.PARAM_LIST, type = CommandType.MAP, description = "param list. Example: param[0].name=cookiename&param[0].value=LBCookie ")
7575
private Map paramList;
7676

77+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
78+
private Boolean display;
79+
80+
7781
// ///////////////////////////////////////////////////
7882
// ///////////////// Accessors ///////////////////////
7983
// ///////////////////////////////////////////////////
8084

85+
public Boolean getDisplay() {
86+
return display;
87+
}
88+
8189
public Long getLbRuleId() {
8290
return lbRuleId;
8391
}

api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.apache.log4j.Logger;
23-
22+
import org.apache.cloudstack.acl.RoleType;
2423
import org.apache.cloudstack.api.APICommand;
2524
import org.apache.cloudstack.api.ApiConstants;
2625
import org.apache.cloudstack.api.BaseListCmd;
2726
import org.apache.cloudstack.api.Parameter;
2827
import org.apache.cloudstack.api.response.FirewallRuleResponse;
2928
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
3029
import org.apache.cloudstack.api.response.ListResponse;
30+
import org.apache.log4j.Logger;
3131

3232
import com.cloud.network.rules.HealthCheckPolicy;
3333
import com.cloud.network.rules.LoadBalancer;
@@ -49,13 +49,23 @@ public class ListLBHealthCheckPoliciesCmd extends BaseListCmd {
4949
description = "the ID of the load balancer rule")
5050
private Long lbRuleId;
5151

52+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
53+
private Boolean display;
54+
5255
// ///////////////////////////////////////////////////
5356
// ///////////////// Accessors ///////////////////////
5457
// ///////////////////////////////////////////////////
5558
public Long getLbRuleId() {
5659
return lbRuleId;
5760
}
5861

62+
public boolean getDisplay() {
63+
if (display != null) {
64+
return display;
65+
}
66+
return true;
67+
}
68+
5969
// ///////////////////////////////////////////////////
6070
// ///////////// API Implementation///////////////////
6171
// ///////////////////////////////////////////////////

api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.apache.log4j.Logger;
23-
22+
import org.apache.cloudstack.acl.RoleType;
2423
import org.apache.cloudstack.api.APICommand;
2524
import org.apache.cloudstack.api.ApiConstants;
2625
import org.apache.cloudstack.api.BaseListCmd;
@@ -29,6 +28,7 @@
2928
import org.apache.cloudstack.api.response.LBStickinessResponse;
3029
import org.apache.cloudstack.api.response.ListResponse;
3130
import org.apache.cloudstack.context.CallContext;
31+
import org.apache.log4j.Logger;
3232

3333
import com.cloud.network.rules.LoadBalancer;
3434
import com.cloud.network.rules.StickinessPolicy;
@@ -51,13 +51,23 @@ public class ListLBStickinessPoliciesCmd extends BaseListCmd {
5151
description = "the ID of the load balancer rule")
5252
private Long lbRuleId;
5353

54+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
55+
private Boolean display;
56+
5457
// ///////////////////////////////////////////////////
5558
// ///////////////// Accessors ///////////////////////
5659
// ///////////////////////////////////////////////////
5760
public Long getLbRuleId() {
5861
return lbRuleId;
5962
}
6063

64+
public boolean getDisplay() {
65+
if (display != null) {
66+
return display;
67+
}
68+
return true;
69+
}
70+
6171
// ///////////////////////////////////////////////////
6272
// ///////////// API Implementation///////////////////
6373
// ///////////////////////////////////////////////////
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package org.apache.cloudstack.api.command.user.loadbalancer;
14+
15+
import org.apache.cloudstack.acl.RoleType;
16+
import org.apache.cloudstack.api.APICommand;
17+
import org.apache.cloudstack.api.ApiConstants;
18+
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
19+
import org.apache.cloudstack.api.Parameter;
20+
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
21+
import org.apache.cloudstack.context.CallContext;
22+
import org.apache.log4j.Logger;
23+
24+
import com.cloud.event.EventTypes;
25+
import com.cloud.network.rules.HealthCheckPolicy;
26+
import com.cloud.network.rules.LoadBalancer;
27+
import com.cloud.network.rules.StickinessPolicy;
28+
import com.cloud.user.Account;
29+
30+
@APICommand(name = "updateLBHealthCheckPolicy", description = "Updates LB HealthCheck policy", responseObject = LBHealthCheckResponse.class, since = "4.4",
31+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
32+
public class UpdateLBHealthCheckPolicyCmd extends BaseAsyncCustomIdCmd{
33+
public static final Logger s_logger = Logger.getLogger(UpdateLBHealthCheckPolicyCmd.class.getName());
34+
35+
private static final String s_name = "updatelbhealthcheckpolicyresponse";
36+
37+
/////////////////////////////////////////////////////
38+
//////////////// API parameters /////////////////////
39+
/////////////////////////////////////////////////////
40+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LBHealthCheckResponse.class, required = true, description = "id of lb healthcheck policy")
41+
private Long id;
42+
43+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the policy to the end user or not", since = "4.4", authorized = {RoleType.Admin})
44+
private Boolean display;
45+
46+
/////////////////////////////////////////////////////
47+
/////////////////// Accessors ///////////////////////
48+
/////////////////////////////////////////////////////
49+
public Long getId() {
50+
return id;
51+
}
52+
53+
public Boolean getDisplay() {
54+
return display;
55+
}
56+
57+
@Override
58+
public String getCommandName() {
59+
return s_name;
60+
}
61+
62+
@Override
63+
public long getEntityOwnerId() {
64+
Account account = CallContext.current().getCallingAccount();
65+
if (account != null) {
66+
return account.getId();
67+
}
68+
69+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
70+
}
71+
72+
@Override
73+
public String getEventDescription() {
74+
return "Update LB healthcheck policy id= " + id;
75+
}
76+
77+
@Override
78+
public String getEventType() {
79+
return EventTypes.EVENT_LB_HEALTHCHECKPOLICY_UPDATE;
80+
}
81+
82+
/////////////////////////////////////////////////////
83+
/////////////// API Implementation///////////////////
84+
/////////////////////////////////////////////////////
85+
@Override
86+
public void execute() {
87+
HealthCheckPolicy policy = _lbService.updateLBHealthCheckPolicy(this.getId(), this.getCustomId(), this.getDisplay());
88+
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
89+
LBHealthCheckResponse hcResponse = _responseGenerator.createLBHealthCheckPolicyResponse(policy, lb);
90+
setResponseObject(hcResponse);
91+
hcResponse.setResponseName(getCommandName());
92+
}
93+
94+
@Override
95+
public void checkUuid() {
96+
if (this.getCustomId() != null) {
97+
_uuidMgr.checkUuid(this.getCustomId(), StickinessPolicy.class);
98+
}
99+
}
100+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
//
12+
// Automatically generated by addcopyright.py at 04/03/2012
13+
package org.apache.cloudstack.api.command.user.loadbalancer;
14+
15+
import org.apache.cloudstack.acl.RoleType;
16+
import org.apache.cloudstack.api.APICommand;
17+
import org.apache.cloudstack.api.ApiConstants;
18+
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
19+
import org.apache.cloudstack.api.Parameter;
20+
import org.apache.cloudstack.api.response.LBStickinessResponse;
21+
import org.apache.cloudstack.context.CallContext;
22+
import org.apache.log4j.Logger;
23+
24+
import com.cloud.event.EventTypes;
25+
import com.cloud.network.rules.LoadBalancer;
26+
import com.cloud.network.rules.StickinessPolicy;
27+
import com.cloud.user.Account;
28+
29+
@APICommand(name = "updateLBStickinessPolicy", description = "Updates LB Stickiness policy", responseObject = LBStickinessResponse.class, since = "4.4",
30+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
31+
public class UpdateLBStickinessPolicyCmd extends BaseAsyncCustomIdCmd{
32+
public static final Logger s_logger = Logger.getLogger(UpdateLBStickinessPolicyCmd.class.getName());
33+
34+
private static final String s_name = "updatelbstickinesspolicyresponse";
35+
36+
/////////////////////////////////////////////////////
37+
//////////////// API parameters /////////////////////
38+
/////////////////////////////////////////////////////
39+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LBStickinessResponse.class, required = true, description = "id of lb stickiness policy")
40+
private Long id;
41+
42+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the policy to the end user or not", since = "4.4", authorized = {RoleType.Admin})
43+
private Boolean display;
44+
45+
/////////////////////////////////////////////////////
46+
/////////////////// Accessors ///////////////////////
47+
/////////////////////////////////////////////////////
48+
public Long getId() {
49+
return id;
50+
}
51+
52+
public Boolean getDisplay() {
53+
return display;
54+
}
55+
56+
@Override
57+
public String getCommandName() {
58+
return s_name;
59+
}
60+
61+
@Override
62+
public long getEntityOwnerId() {
63+
Account account = CallContext.current().getCallingAccount();
64+
if (account != null) {
65+
return account.getId();
66+
}
67+
68+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
69+
}
70+
71+
@Override
72+
public String getEventDescription() {
73+
return "Update LB stickiness policy id= " + id;
74+
}
75+
76+
@Override
77+
public String getEventType() {
78+
return EventTypes.EVENT_LB_STICKINESSPOLICY_UPDATE;
79+
}
80+
81+
/////////////////////////////////////////////////////
82+
/////////////// API Implementation///////////////////
83+
/////////////////////////////////////////////////////
84+
@Override
85+
public void execute() {
86+
StickinessPolicy policy = _lbService.updateLBStickinessPolicy(this.getId(), this.getCustomId(), this.getDisplay());
87+
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
88+
LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
89+
setResponseObject(spResponse);
90+
spResponse.setResponseName(getCommandName());
91+
}
92+
93+
@Override
94+
public void checkUuid() {
95+
if (this.getCustomId() != null) {
96+
_uuidMgr.checkUuid(this.getCustomId(), StickinessPolicy.class);
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)