mirror of https://github.com/apache/cloudstack.git
External UUID control support for NetworkACLList/LoadBalancer/ApplicationLoadBalancer
This commit is contained in:
parent
3cfa5fbfe1
commit
9641e1dbee
|
|
@ -365,6 +365,7 @@ public class EventTypes {
|
|||
public static final String EVENT_NETWORK_ACL_CREATE = "NETWORK.ACL.CREATE";
|
||||
public static final String EVENT_NETWORK_ACL_DELETE = "NETWORK.ACL.DELETE";
|
||||
public static final String EVENT_NETWORK_ACL_REPLACE = "NETWORK.ACL.REPLACE";
|
||||
public static final String EVENT_NETWORK_ACL_UPDATE = "NETWORK.ACL.UPDATE";
|
||||
public static final String EVENT_NETWORK_ACL_ITEM_CREATE = "NETWORK.ACL.ITEM.CREATE";
|
||||
public static final String EVENT_NETWORK_ACL_ITEM_UPDATE = "NETWORK.ACL.ITEM.UPDATE";
|
||||
public static final String EVENT_NETWORK_ACL_ITEM_DELETE = "NETWORK.ACL.ITEM.DELETE";
|
||||
|
|
|
|||
|
|
@ -130,4 +130,6 @@ public interface NetworkACLService {
|
|||
*/
|
||||
boolean replaceNetworkACLonPrivateGw(long aclId, long privateGatewayId) throws ResourceUnavailableException;
|
||||
|
||||
NetworkACL updateNetworkACL(Long id, String customId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
// 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 org.apache.cloudstack.api.command.user.loadbalancer;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
|
||||
import org.apache.cloudstack.api.response.FirewallRuleResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
||||
@APICommand(name = "updateLoadBalancer", description = "Updates a Load Balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.4.0")
|
||||
public class UpdateApplicationLoadBalancerCmd extends BaseAsyncCustomIdCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateApplicationLoadBalancerCmd.class.getName());
|
||||
|
||||
private static final String s_name = "updateloadbalancerresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the Load Balancer")
|
||||
private Long id;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
ApplicationLoadBalancerRule lb = _entityMgr.findById(ApplicationLoadBalancerRule.class, getId());
|
||||
if (lb != null) {
|
||||
return lb.getAccountId();
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Can't find load balancer by id specified");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_LOAD_BALANCER_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "updating load balancer: " + getId();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@Override
|
||||
public void execute() {
|
||||
CallContext.current().setEventDetails("Load balancer Id: " + getId());
|
||||
ApplicationLoadBalancerRule rule = _appLbService.deleteApplicationLoadBalancer(getId(), this.getCustomId());
|
||||
ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getId()));
|
||||
setResponseObject(lbResponse);
|
||||
lbResponse.setResponseName(getCommandName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUuid() {
|
||||
if (this.getCustomId() != null) {
|
||||
_uuidMgr.checkUuid(this.getCustomId(), ApplicationLoadBalancerRule.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,17 +16,17 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.loadbalancer;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.FirewallRuleResponse;
|
||||
import org.apache.cloudstack.api.response.LoadBalancerResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
|
@ -34,7 +34,7 @@ import com.cloud.network.rules.LoadBalancer;
|
|||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "updateLoadBalancerRule", description = "Updates load balancer", responseObject = LoadBalancerResponse.class)
|
||||
public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
|
||||
public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateLoadBalancerRuleCmd.class.getName());
|
||||
private static final String s_name = "updateloadbalancerruleresponse";
|
||||
|
||||
|
|
@ -132,4 +132,11 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
|
|||
}
|
||||
return lb.getNetworkId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUuid() {
|
||||
if (this.getCustomId() != null) {
|
||||
_uuidMgr.checkUuid(this.getCustomId(), LoadBalancer.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,91 @@
|
|||
// 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 org.apache.cloudstack.api.command.user.network;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.NetworkACLResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.vpc.NetworkACL;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "updateNetworkACLList", description = "Updates Network ACL list", responseObject = SuccessResponse.class, since = "4.4")
|
||||
public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLListCmd.class.getName());
|
||||
private static final String s_name = "updatenetworkacllistresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = NetworkACLResponse.class, required = true, description = "the ID of the network ACL")
|
||||
private Long id;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_NETWORK_ACL_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return ("Updating network acl list id=" + id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
return caller.getAccountId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException {
|
||||
NetworkACL acl = _networkACLService.updateNetworkACL(id, this.getCustomId());
|
||||
NetworkACLResponse aclResponse = _responseGenerator.createNetworkACLResponse(acl);
|
||||
setResponseObject(aclResponse);
|
||||
aclResponse.setResponseName(getCommandName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUuid() {
|
||||
if (this.getCustomId() != null) {
|
||||
_uuidMgr.checkUuid(this.getCustomId(), NetworkACL.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,4 +39,6 @@ public interface ApplicationLoadBalancerService {
|
|||
|
||||
ApplicationLoadBalancerRule getApplicationLoadBalancer(long ruleId);
|
||||
|
||||
ApplicationLoadBalancerRule deleteApplicationLoadBalancer(Long id, String customId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -471,6 +471,7 @@ createNetworkACLList=15
|
|||
deleteNetworkACLList=15
|
||||
replaceNetworkACLList=15
|
||||
listNetworkACLLists=15
|
||||
updateNetworkACLList=15
|
||||
|
||||
|
||||
#### Static route commands
|
||||
|
|
@ -653,6 +654,7 @@ removedeleteUcsManager=1
|
|||
createLoadBalancer=15
|
||||
listLoadBalancers=15
|
||||
deleteLoadBalancer=15
|
||||
updateLoadBalancer=15
|
||||
|
||||
#Internal Load Balancer Element commands
|
||||
configureInternalLoadBalancerElement=7
|
||||
|
|
|
|||
|
|
@ -82,4 +82,7 @@ public class NetworkACLVO implements NetworkACL {
|
|||
return name;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1888,6 +1888,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
String algorithm = cmd.getAlgorithm();
|
||||
LoadBalancerVO lb = _lbDao.findById(lbRuleId);
|
||||
LoadBalancerVO lbBackup = _lbDao.findById(lbRuleId);
|
||||
String customId = cmd.getCustomId();
|
||||
|
||||
if (lb == null) {
|
||||
throw new InvalidParameterValueException("Unable to find lb rule by id=" + lbRuleId);
|
||||
|
|
@ -1908,6 +1909,10 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
lb.setAlgorithm(algorithm);
|
||||
}
|
||||
|
||||
if (customId != null) {
|
||||
lb.setUuid(customId);
|
||||
}
|
||||
|
||||
boolean success = _lbDao.update(lbRuleId, lb);
|
||||
|
||||
// If algorithm is changed, have to reapply the lb config
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
|
|
@ -637,4 +639,20 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
|
|||
return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType, newUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_UPDATE, eventDescription = "updating network acl", async = true)
|
||||
public NetworkACL updateNetworkACL(Long id, String customId) {
|
||||
NetworkACLVO acl = _networkACLDao.findById(id);
|
||||
Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
_accountMgr.checkAccess(caller, null, true, vpc);
|
||||
|
||||
if (customId != null) {
|
||||
acl.setUuid(customId);
|
||||
}
|
||||
|
||||
_networkACLDao.update(id, acl);
|
||||
return _networkACLDao.findById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -294,6 +294,7 @@ import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRules
|
|||
import org.apache.cloudstack.api.command.user.loadbalancer.ListSslCertsCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.RemoveCertFromLoadBalancerCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.RemoveFromLoadBalancerRuleCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.UpdateApplicationLoadBalancerCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd;
|
||||
import org.apache.cloudstack.api.command.user.nat.CreateIpForwardingRuleCmd;
|
||||
|
|
@ -314,6 +315,7 @@ import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
|
|||
import org.apache.cloudstack.api.command.user.network.ReplaceNetworkACLListCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLItemCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.UpdateNetworkCmd;
|
||||
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
|
||||
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
|
||||
|
|
@ -2853,6 +2855,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
cmdList.add(GetVMUserDataCmd.class);
|
||||
cmdList.add(UpdateEgressFirewallRuleCmd.class);
|
||||
cmdList.add(UpdateFirewallRuleCmd.class);
|
||||
cmdList.add(UpdateNetworkACLListCmd.class);
|
||||
cmdList.add(UpdateApplicationLoadBalancerCmd.class);
|
||||
return cmdList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,15 +24,14 @@ import java.util.Map;
|
|||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.ListApplicationLoadBalancersCmd;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
|
||||
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.EventTypes;
|
||||
|
|
@ -525,4 +524,22 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A
|
|||
s_logger.debug("No network rule conflicts detected for " + newLbRule + " against " + (lbRules.size() - 1) + " existing rules");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_UPDATE, eventDescription = "updating load balancer", async = true)
|
||||
public ApplicationLoadBalancerRule deleteApplicationLoadBalancer(Long id, String customId) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
ApplicationLoadBalancerRuleVO rule = _lbDao.findById(id);
|
||||
|
||||
if (rule == null) {
|
||||
throw new InvalidParameterValueException("Unable to find load balancer " + id);
|
||||
}
|
||||
_accountMgr.checkAccess(caller, null, true, rule);
|
||||
if (customId != null) {
|
||||
rule.setUuid(customId);
|
||||
}
|
||||
_lbDao.update(id, rule);
|
||||
|
||||
return _lbDao.findById(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue