Search in sources :

Example 81 with Network

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);
    }
}
Also used : NoTransitionException(com.cloud.utils.fsm.NoTransitionException) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands)

Example 82 with Network

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;
}
Also used : Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) CreateNetworkCommand(com.cloud.agent.api.CreateNetworkCommand) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 83 with Network

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);
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeploymentPlan(com.cloud.deploy.DeploymentPlan) Test(org.junit.Test)

Example 84 with Network

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());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) ArrayList(java.util.ArrayList)

Example 85 with Network

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);
        }
    }
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) TransactionStatus(com.cloud.utils.db.TransactionStatus) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Aggregations

Network (com.cloud.network.Network)235 ArrayList (java.util.ArrayList)86 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)63 Account (com.cloud.user.Account)60 Test (org.junit.Test)55 NetworkOffering (com.cloud.offering.NetworkOffering)52 PhysicalNetwork (com.cloud.network.PhysicalNetwork)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)50 NetworkVO (com.cloud.network.dao.NetworkVO)38 DataCenter (com.cloud.dc.DataCenter)34 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 NicProfile (com.cloud.vm.NicProfile)31 HostVO (com.cloud.host.HostVO)27 DB (com.cloud.utils.db.DB)27 List (java.util.List)27 DataCenterVO (com.cloud.dc.DataCenterVO)26 IPAddressVO (com.cloud.network.dao.IPAddressVO)25 HashMap (java.util.HashMap)24 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)23 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20