use of com.cloud.network.Network in project cloudstack by apache.
the class VirtualMachineManagerImpl method ensureVmRunningContext.
private void ensureVmRunningContext(final long hostId, VMInstanceVO vm, final Event cause) throws OperationTimedoutException, ResourceUnavailableException, NoTransitionException, InsufficientAddressCapacityException {
final VirtualMachineGuru vmGuru = getVmGuru(vm);
s_logger.debug("VM state is starting on full sync so updating it to running");
vm = _vmDao.findById(vm.getId());
// grab outstanding work item if any
final ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState());
if (work != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found an outstanding work item for this vm " + vm + " in state:" + vm.getState() + ", work id:" + work.getId());
}
}
try {
stateTransitTo(vm, cause, hostId);
} catch (final NoTransitionException e1) {
s_logger.warn(e1.getMessage());
}
s_logger.debug("VM's " + vm + " state is starting on full sync so updating it to Running");
// this should ensure vm has the most
vm = _vmDao.findById(vm.getId());
// up to date info
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
final List<NicVO> nics = _nicsDao.listByVmId(profile.getId());
for (final NicVO nic : nics) {
final Network network = _networkModel.getNetwork(nic.getNetworkId());
final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(profile.getHypervisorType(), network));
profile.addNic(nicProfile);
}
final Commands cmds = new Commands(Command.OnError.Stop);
s_logger.debug("Finalizing commands that need to be send to complete Start process for the vm " + vm);
if (vmGuru.finalizeCommandsOnStart(cmds, profile)) {
if (cmds.size() != 0) {
_agentMgr.send(vm.getHostId(), cmds);
}
if (vmGuru.finalizeStart(profile, vm.getHostId(), cmds, null)) {
stateTransitTo(vm, cause, vm.getHostId());
} else {
s_logger.error("Unable to finish finialization for running vm: " + vm);
}
} else {
s_logger.error("Unable to finalize commands on start for vm: " + vm);
}
if (work != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Updating outstanding work item to Done, id:" + work.getId());
}
work.setStep(Step.Done);
_workDao.update(work.getId(), work);
}
}
use of com.cloud.network.Network in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
Network implemented = super.implement(network, offering, dest, context);
int vlanTag = Integer.parseInt(BroadcastDomainType.getValue(implemented.getBroadcastUri()));
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Brocade VCS Switch on physical network " + physicalNetworkId);
return null;
}
for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) {
HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId());
// create createNetworkCmd instance and agentMgr execute it.
CreateNetworkCommand cmd = new CreateNetworkCommand(vlanTag, network.getId(), context.getDomain().getName() + "-" + context.getAccount().getAccountName());
CreateNetworkAnswer answer = (CreateNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("CreateNetworkCommand failed");
s_logger.error("Unable to create network " + network.getId());
return null;
}
}
// Persist the network-vlan mapping from db
BrocadeVcsNetworkVlanMappingVO brocadeVcsNetworkVlanMapping = new BrocadeVcsNetworkVlanMappingVO(network.getId(), vlanTag);
_brocadeVcsNetworkVlanDao.persist(brocadeVcsNetworkVlanMapping);
return implemented;
}
use of com.cloud.network.Network in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testDesignNoConnectivityInOffering.
@Test
public void testDesignNoConnectivityInOffering() {
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
when(physnet.getId()).thenReturn(NETWORK_ID);
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
final DeploymentPlan plan = mock(DeploymentPlan.class);
final Network network = mock(Network.class);
final Account account = mock(Account.class);
final Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
use of com.cloud.network.Network in project cloudstack by apache.
the class ListNiciraNvpDeviceNetworksCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
List<? extends Network> networks = niciraNvpElementService.listNiciraNvpDeviceNetworks(this);
ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
if (networks != null && !networks.isEmpty()) {
for (Network network : networks) {
NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Full, network);
networkResponses.add(networkResponse);
}
}
response.setResponses(networkResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
use of com.cloud.network.Network in project cloudstack by apache.
the class ApplicationLoadBalancerManagerImpl method persistLbRule.
@DB
protected ApplicationLoadBalancerRule persistLbRule(final ApplicationLoadBalancerRuleVO newRuleFinal) throws NetworkRuleConflictException {
boolean success = true;
ApplicationLoadBalancerRuleVO newRule = null;
try {
newRule = Transaction.execute(new TransactionCallbackWithException<ApplicationLoadBalancerRuleVO, NetworkRuleConflictException>() {
@Override
public ApplicationLoadBalancerRuleVO doInTransaction(TransactionStatus status) throws NetworkRuleConflictException {
//1) Persist the rule
ApplicationLoadBalancerRuleVO newRule = _lbDao.persist(newRuleFinal);
//2) Detect conflicts
detectLbRulesConflicts(newRule);
if (!_firewallDao.setStateToAdd(newRule)) {
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
}
s_logger.debug("Load balancer " + newRule.getId() + " for Ip address " + newRule.getSourceIp().addr() + ", source port " + newRule.getSourcePortStart().intValue() + ", instance port " + newRule.getDefaultPortStart() + " is added successfully.");
CallContext.current().setEventDetails("Load balancer Id: " + newRule.getId());
Network ntwk = _networkModel.getNetwork(newRule.getNetworkId());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_LOAD_BALANCER_CREATE, newRule.getAccountId(), ntwk.getDataCenterId(), newRule.getId(), null, LoadBalancingRule.class.getName(), newRule.getUuid());
return newRule;
}
});
return newRule;
} catch (Exception e) {
success = false;
if (e instanceof NetworkRuleConflictException) {
throw (NetworkRuleConflictException) e;
}
throw new CloudRuntimeException("Unable to add lb rule for ip address " + newRuleFinal.getSourceIpAddressId(), e);
} finally {
if (!success && newRule != null) {
_lbMgr.removeLBRule(newRule);
}
}
}
Aggregations