use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class ListVmwareDcsCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
List<? extends VmwareDatacenter> vmwareDcList = null;
try {
vmwareDcList = _vmwareDatacenterService.listVmwareDatacenters(this);
} catch (InvalidParameterValueException ie) {
throw new InvalidParameterValueException("Invalid zone id " + getZoneId());
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to find associated VMware DCs associated with zone " + getZoneId());
}
ListResponse<VmwareDatacenterResponse> response = new ListResponse<VmwareDatacenterResponse>();
List<VmwareDatacenterResponse> vmwareDcResponses = new ArrayList<VmwareDatacenterResponse>();
if (vmwareDcList != null && vmwareDcList.size() > 0) {
for (VmwareDatacenter vmwareDc : vmwareDcList) {
VmwareDatacenterResponse vmwareDcResponse = new VmwareDatacenterResponse();
vmwareDcResponse.setId(vmwareDc.getUuid());
vmwareDcResponse.setVcenter(vmwareDc.getVcenterHost());
vmwareDcResponse.setName(vmwareDc.getVmwareDatacenterName());
vmwareDcResponse.setZoneId(getZoneId());
vmwareDcResponse.setObjectName("VMwareDC");
vmwareDcResponses.add(vmwareDcResponse);
}
}
response.setResponses(vmwareDcResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class MidoNetElementTest method testImplement.
/*
* Test the standard case of implement with no errors.
*/
public void testImplement() {
//mock
MidonetApi api = mock(MidonetApi.class, RETURNS_DEEP_STUBS);
//mockAccountDao
AccountDao mockAccountDao = mock(AccountDao.class);
AccountVO mockAccountVO = mock(AccountVO.class);
when(mockAccountDao.findById(anyLong())).thenReturn(mockAccountVO);
when(mockAccountVO.getUuid()).thenReturn("1");
MidoNetElement elem = new MidoNetElement();
elem.setMidonetApi(api);
elem.setAccountDao(mockAccountDao);
//mockRPort
RouterPort mockRPort = mock(RouterPort.class);
when(mockRPort.getId()).thenReturn(UUID.fromString("550e8400-e29b-41d4-a716-446655440000"));
//mockBPort
BridgePort mockBPort = mock(BridgePort.class);
when(mockBPort.link(any(UUID.class))).thenReturn(mockBPort);
//mockPort
Port mockPort = mock(Port.class);
ResourceCollection<Port> peerPorts = new ResourceCollection<Port>(new ArrayList<Port>());
peerPorts.add(mockPort);
//mockBridge
Bridge mockBridge = mock(Bridge.class, RETURNS_DEEP_STUBS);
when(api.addBridge().tenantId(anyString()).name(anyString()).create()).thenReturn(mockBridge);
when(mockBridge.addInteriorPort().create()).thenReturn(mockBPort);
when(mockBridge.getPeerPorts()).thenReturn(peerPorts);
//mockRouter
Router mockRouter = mock(Router.class, RETURNS_DEEP_STUBS);
when(api.addRouter().tenantId(anyString()).name(anyString()).create()).thenReturn(mockRouter);
when(mockRouter.addInteriorRouterPort().create()).thenReturn(mockRPort);
//mockNetwork
Network mockNetwork = mock(Network.class);
when(mockNetwork.getAccountId()).thenReturn((long) 1);
when(mockNetwork.getGateway()).thenReturn("1.2.3.4");
when(mockNetwork.getCidr()).thenReturn("1.2.3.0/24");
when(mockNetwork.getId()).thenReturn((long) 2);
when(mockNetwork.getBroadcastDomainType()).thenReturn(Networks.BroadcastDomainType.Mido);
when(mockNetwork.getTrafficType()).thenReturn(Networks.TrafficType.Public);
boolean result = false;
try {
result = elem.implement(mockNetwork, null, null, null);
} catch (ConcurrentOperationException e) {
fail(e.getMessage());
} catch (InsufficientCapacityException e) {
fail(e.getMessage());
} catch (ResourceUnavailableException e) {
fail(e.getMessage());
}
assertEquals(result, true);
}
use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class ConsoleProxyManagerImpl method startProxy.
@Override
public ConsoleProxyVO startProxy(long proxyVmId, boolean ignoreRestartSetting) {
try {
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
if (proxy.getState() == VirtualMachine.State.Running) {
return proxy;
}
String restart = _configDao.getValue(Config.ConsoleProxyRestart.key());
if (!ignoreRestartSetting && restart != null && restart.equalsIgnoreCase("false")) {
return null;
}
if (proxy.getState() == VirtualMachine.State.Stopped) {
_itMgr.advanceStart(proxy.getUuid(), null, null);
proxy = _consoleProxyDao.findById(proxy.getId());
return proxy;
}
// For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null
// as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited
// to Stopped to allow Starting of it
s_logger.warn("Console proxy is not in correct state to be started: " + proxy.getState());
return null;
} catch (StorageUnavailableException e) {
s_logger.warn("Exception while trying to start console proxy", e);
return null;
} catch (InsufficientCapacityException e) {
s_logger.warn("Exception while trying to start console proxy", e);
return null;
} catch (ResourceUnavailableException e) {
s_logger.warn("Exception while trying to start console proxy", e);
return null;
} catch (ConcurrentOperationException e) {
s_logger.warn("Runtime Exception while trying to start console proxy", e);
return null;
} catch (CloudRuntimeException e) {
s_logger.warn("Runtime Exception while trying to start console proxy", e);
return null;
} catch (OperationTimedoutException e) {
s_logger.warn("Runtime Exception while trying to start console proxy", e);
return null;
}
}
use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class NicPlugInOutRules method accept.
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = getNicsToChangeOnRouter(visitor);
Map<String, PublicIpAddress> nicsToPlug = nicsToChange.first();
Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
VirtualMachineManager itMgr = visitor.getVirtualNetworkApplianceFactory().getItMgr();
// 1) Unplug the nics
for (Entry<String, PublicIpAddress> entry : nicsToUnplug.entrySet()) {
Network publicNtwk = null;
try {
publicNtwk = networkModel.getNetwork(entry.getValue().getNetworkId());
URI broadcastUri = BroadcastDomainType.Vlan.toUri(entry.getKey());
itMgr.removeVmFromNetwork(_router, publicNtwk, broadcastUri);
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to remove router " + _router + " from vlan " + entry.getKey() + " in public network " + publicNtwk + " due to ", e);
return false;
}
}
_netUsageCommands = new Commands(Command.OnError.Continue);
VpcDao vpcDao = visitor.getVirtualNetworkApplianceFactory().getVpcDao();
VpcVO vpc = vpcDao.findById(_router.getVpcId());
// 2) Plug the nics
for (String vlanTag : nicsToPlug.keySet()) {
PublicIpAddress ip = nicsToPlug.get(vlanTag);
// have to plug the nic(s)
NicProfile defaultNic = new NicProfile();
if (ip.isSourceNat()) {
defaultNic.setDefaultNic(true);
}
defaultNic.setIPv4Address(ip.getAddress().addr());
defaultNic.setIPv4Gateway(ip.getGateway());
defaultNic.setIPv4Netmask(ip.getNetmask());
defaultNic.setMacAddress(ip.getMacAddress());
defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
defaultNic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
NicProfile publicNic = null;
Network publicNtwk = null;
try {
publicNtwk = networkModel.getNetwork(ip.getNetworkId());
publicNic = itMgr.addVmToNetwork(_router, publicNtwk, defaultNic);
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
} catch (InsufficientCapacityException e) {
s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
} finally {
if (publicNic == null) {
s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk);
return false;
}
}
// Create network usage commands. Send commands to router after
// IPAssoc
NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(_router.getPrivateIpAddress(), _router.getInstanceName(), true, defaultNic.getIPv4Address(), vpc.getCidr());
_netUsageCommands.addCommand(netUsageCmd);
UserStatisticsDao userStatsDao = visitor.getVirtualNetworkApplianceFactory().getUserStatsDao();
UserStatisticsVO stats = userStatsDao.findBy(_router.getAccountId(), _router.getDataCenterId(), publicNtwk.getId(), publicNic.getIPv4Address(), _router.getId(), _router.getType().toString());
if (stats == null) {
stats = new UserStatisticsVO(_router.getAccountId(), _router.getDataCenterId(), publicNic.getIPv4Address(), _router.getId(), _router.getType().toString(), publicNtwk.getId());
userStatsDao.persist(stats);
}
}
// VpcIpAssociation is done.
return true;
}
use of com.cloud.exception.ConcurrentOperationException in project cloudstack by apache.
the class CreatePrivateGatewayCmd method create.
@Override
public void create() throws ResourceAllocationException {
PrivateGateway result = null;
try {
result = _vpcService.createVpcPrivateGateway(getVpcId(), getPhysicalNetworkId(), getBroadcastUri(), getStartIp(), getGateway(), getNetmask(), getEntityOwnerId(), getNetworkOfferingId(), getIsSourceNat(), getAclId());
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
s_logger.trace(ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway");
}
}
Aggregations