External UUID control support for VPC and NetworkACLItemp

This commit is contained in:
Alena Prokharchyk 2014-02-04 14:43:50 -08:00
parent 7cd0ad336b
commit 8065ee445f
11 changed files with 60 additions and 31 deletions

View File

@ -114,11 +114,12 @@ public interface NetworkACLService {
* @param sourcePortEnd
* @param icmpCode
* @param icmpType
* @param newUUID TODO
* @return
* @throws ResourceUnavailableException
*/
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number,
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException;
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID) throws ResourceUnavailableException;
/**
* Associates ACL with specified Network

View File

@ -66,9 +66,10 @@ public interface VpcService {
* @param vpcId
* @param vpcName
* @param displayText
* @param customId TODO
* @return
*/
public Vpc updateVpc(long vpcId, String vpcName, String displayText);
public Vpc updateVpc(long vpcId, String vpcName, String displayText, String customId);
/**
* Lists VPC(s) based on the parameters passed to the method call

View File

@ -18,16 +18,15 @@ package org.apache.cloudstack.api.command.user.network;
import java.util.List;
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.NetworkACLItemResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.ResourceUnavailableException;
@ -35,7 +34,7 @@ import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.user.Account;
@APICommand(name = "updateNetworkACLItem", description = "Updates ACL Item with specified Id", responseObject = NetworkACLItemResponse.class)
public class UpdateNetworkACLItemCmd extends BaseAsyncCmd {
public class UpdateNetworkACLItemCmd extends BaseAsyncCustomIdCmd {
public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLItemCmd.class.getName());
private static final String s_name = "createnetworkaclresponse";
@ -165,7 +164,7 @@ public class UpdateNetworkACLItemCmd extends BaseAsyncCmd {
CallContext.current().setEventDetails("Rule Id: " + getId());
NetworkACLItem aclItem =
_networkACLService.updateNetworkACLItem(getId(), getProtocol(), getSourceCidrList(), getTrafficType(), getAction(), getNumber(), getSourcePortStart(),
getSourcePortEnd(), getIcmpCode(), getIcmpType());
getSourcePortEnd(), getIcmpCode(), getIcmpType(), this.getCustomId());
if (aclItem == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network ACL Item");
}
@ -174,4 +173,11 @@ public class UpdateNetworkACLItemCmd extends BaseAsyncCmd {
aclResponse.setResponseName(getCommandName());
}
@Override
public void checkUuid(String id, Class<?> cls) {
if (this.getCustomId() != null) {
_uuidMgr.checkUuid(this.getCustomId(), NetworkACLItem.class);
}
}
}

View File

@ -16,22 +16,22 @@
// under the License.
package org.apache.cloudstack.api.command.user.vpc;
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.VpcResponse;
import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.network.vpc.Vpc;
import com.cloud.user.Account;
@APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class)
public class UpdateVPCCmd extends BaseAsyncCmd {
public class UpdateVPCCmd extends BaseAsyncCustomIdCmd {
public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName());
private static final String Name = "updatevpcresponse";
@ -84,7 +84,7 @@ public class UpdateVPCCmd extends BaseAsyncCmd {
@Override
public void execute() {
Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText());
Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), this.getCustomId());
if (result != null) {
VpcResponse response = _responseGenerator.createVpcResponse(result);
response.setResponseName(getCommandName());
@ -113,4 +113,11 @@ public class UpdateVPCCmd extends BaseAsyncCmd {
public Long getSyncObjId() {
return getId();
}
@Override
public void checkUuid(String id, Class<?> cls) {
if (this.getCustomId() != null) {
_uuidMgr.checkUuid(this.getCustomId(), Vpc.class);
}
}
}

View File

@ -130,11 +130,12 @@ public interface NetworkACLManager {
* @param sourcePortEnd
* @param icmpCode
* @param icmpType
* @param customId TODO
* @return
* @throws ResourceUnavailableException
*/
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number,
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException;
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String customId) throws ResourceUnavailableException;
/**
* Associates acl with a network and applies the ACLItems

View File

@ -241,4 +241,8 @@ public class NetworkACLItemVO implements NetworkACLItem {
public void setAction(Action action) {
this.action = action;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -31,6 +31,7 @@ import com.cloud.utils.db.GenericDao;
@Entity
@Table(name = "vpc")
public class VpcVO implements Vpc {
@Id
@Column(name = "id")
long id;
@ -177,4 +178,8 @@ public class VpcVO implements Vpc {
public boolean isRestartRequired() {
return restartRequired;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -22,9 +22,8 @@ import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.event.ActionEvent;
@ -399,7 +398,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana
@Override
public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action,
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException {
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String customId) throws ResourceUnavailableException {
NetworkACLItemVO aclItem = _networkACLItemDao.findById(id);
aclItem.setState(State.Add);
@ -443,6 +442,10 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana
aclItem.setIcmpType(icmpType);
}
if (customId != null) {
aclItem.setUuid(customId);
}
if (_networkACLItemDao.update(id, aclItem)) {
if (applyNetworkACL(aclItem.getAclId())) {
return aclItem;

View File

@ -23,17 +23,15 @@ import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import com.cloud.network.vpc.dao.VpcDao;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
import org.apache.cloudstack.context.CallContext;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
@ -43,6 +41,7 @@ import com.cloud.network.Networks;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.vpc.dao.NetworkACLDao;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcGatewayDao;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.server.ResourceTag.ResourceObjectType;
@ -606,7 +605,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
@Override
public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action,
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException {
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID) throws ResourceUnavailableException {
NetworkACLItemVO aclItem = _networkACLItemDao.findById(id);
if (aclItem == null) {
throw new InvalidParameterValueException("Unable to find ACL Item cannot be found");
@ -635,7 +634,7 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
validateNetworkACLItem((sourcePortStart == null) ? aclItem.getSourcePortStart() : sourcePortStart, (sourcePortEnd == null) ? aclItem.getSourcePortEnd()
: sourcePortEnd, sourceCidrList, protocol, icmpCode, (icmpType == null) ? aclItem.getIcmpType() : icmpType, action, number);
return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType);
return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType, newUUID);
}
}

View File

@ -32,8 +32,6 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
@ -42,6 +40,7 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationSe
import org.apache.cloudstack.framework.config.ConfigDepot;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.log4j.Logger;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
@ -770,7 +769,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc")
public Vpc updateVpc(long vpcId, String vpcName, String displayText) {
public Vpc updateVpc(long vpcId, String vpcName, String displayText, String customId) {
CallContext.current().setEventDetails(" Id: " + vpcId);
Account caller = CallContext.current().getCallingAccount();
@ -792,6 +791,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
vpc.setDisplayText(displayText);
}
if (customId != null) {
vpc.setUuid(customId);
}
if (_vpcDao.update(vpcId, vpc)) {
s_logger.debug("Updated VPC id=" + vpcId);
return _vpcDao.findById(vpcId);

View File

@ -24,6 +24,9 @@ import javax.inject.Inject;
import junit.framework.TestCase;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.test.utils.SpringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -41,10 +44,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.test.utils.SpringUtils;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
@ -228,7 +227,7 @@ public class NetworkACLManagerTest extends TestCase {
public void testUpdateACLItem() throws Exception {
Mockito.when(_networkACLItemDao.findById(Matchers.anyLong())).thenReturn(aclItem);
Mockito.when(_networkACLItemDao.update(Matchers.anyLong(), Matchers.any(NetworkACLItemVO.class))).thenReturn(true);
assertNotNull(_aclMgr.updateNetworkACLItem(1L, "UDP", null, NetworkACLItem.TrafficType.Ingress, "Deny", 10, 22, 32, null, null));
assertNotNull(_aclMgr.updateNetworkACLItem(1L, "UDP", null, NetworkACLItem.TrafficType.Ingress, "Deny", 10, 22, 32, null, null, null));
}
@Test(expected = CloudRuntimeException.class)