Search in sources :

Example 6 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class NuageVspElementTest method testImplement.

@Test
public void testImplement() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, URISyntaxException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getBroadcastUri()).thenReturn(new URI(""));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(_networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination deployDest = mock(DeployDestination.class);
    final DomainVO dom = mock(DomainVO.class);
    when(dom.getName()).thenReturn("domain");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(dom);
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] { nuageVspDevice }));
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    when(_nuageVspManager.getNuageVspHost(NETWORK_ID)).thenReturn(host);
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress)).thenReturn(new ArrayList<FirewallRuleVO>());
    when(_ipAddressDao.listStaticNatPublicIps(NETWORK_ID)).thenReturn(new ArrayList<IPAddressVO>());
    when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
    assertTrue(_nuageVspElement.implement(network, offering, deployDest, context));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) URI(java.net.URI) HostVO(com.cloud.host.HostVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) ReservationContext(com.cloud.vm.ReservationContext) DomainVO(com.cloud.domain.DomainVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) IPAddressVO(com.cloud.network.dao.IPAddressVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 7 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class VpcManagerImpl method startVpc.

@Override
public boolean startVpc(final long vpcId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(ctx.getCallingUserId());
    // check if vpc exists
    final Vpc vpc = getActiveVpc(vpcId);
    if (vpc == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified");
        ex.addProxyObject(String.valueOf(vpcId), "VPC");
        throw ex;
    }
    // permission check
    _accountMgr.checkAccess(caller, null, false, vpc);
    final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId());
    final DeployDestination dest = new DeployDestination(dc, null, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId()));
    boolean result = true;
    try {
        if (!startVpc(vpc, dest, context)) {
            s_logger.warn("Failed to start vpc " + vpc);
            result = false;
        }
    } catch (final Exception ex) {
        s_logger.warn("Failed to start vpc " + vpc + " due to ", ex);
        result = false;
    } finally {
        // do cleanup
        if (!result && destroyOnFailure) {
            s_logger.debug("Destroying vpc " + vpc + " that failed to start");
            if (destroyVpc(vpc, caller, callerUser.getId())) {
                s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start");
            } else {
                s_logger.warn("Failed to destroy vpc " + vpc + " that failed to start");
            }
        }
    }
    return result;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CallContext(org.apache.cloudstack.context.CallContext) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ReservationContext(com.cloud.vm.ReservationContext)

Example 8 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class GloboDnsElementTest method testPrepareMethodCallGloboDnsToRegisterHostName.

@Test
public void testPrepareMethodCallGloboDnsToRegisterHostName() throws Exception {
    Network network = mock(Network.class);
    when(network.getDataCenterId()).thenReturn(zoneId);
    when(network.getId()).thenReturn(1l);
    NicProfile nic = new NicProfile();
    nic.setIPv4Address("10.11.12.13");
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    when(vm.getHostName()).thenReturn("vm-name");
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    DataCenterVO dataCenterVO = mock(DataCenterVO.class);
    when(dataCenterVO.getId()).thenReturn(zoneId);
    when(_datacenterDao.findById(zoneId)).thenReturn(dataCenterVO);
    DeployDestination dest = new DeployDestination();
    ReservationContext context = new ReservationContextImpl(null, null, user);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(globoDnsHostId);
    when(_hostDao.findByTypeNameAndZoneId(eq(zoneId), eq(Provider.GloboDns.getName()), eq(Type.L2Networking))).thenReturn(hostVO);
    when(_agentMgr.easySend(eq(globoDnsHostId), isA(CreateOrUpdateRecordAndReverseCommand.class))).then(new org.mockito.stubbing.Answer<Answer>() {

        @Override
        public Answer answer(InvocationOnMock invocation) throws Throwable {
            Command cmd = (Command) invocation.getArguments()[1];
            return new Answer(cmd);
        }
    });
    _globodnsElement.prepare(network, nic, vm, dest, context);
    verify(_agentMgr, times(1)).easySend(eq(globoDnsHostId), isA(CreateOrUpdateRecordAndReverseCommand.class));
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Answer(com.cloud.agent.api.Answer) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Command(com.cloud.agent.api.Command) DeployDestination(com.cloud.deploy.DeployDestination) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Network(com.cloud.network.Network) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 9 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class GloboDnsElementTest method testUpperCaseCharactersAreNotAllowed.

@Test(expected = InvalidParameterValueException.class)
public void testUpperCaseCharactersAreNotAllowed() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    Network network = mock(Network.class);
    when(network.getDataCenterId()).thenReturn(zoneId);
    when(network.getId()).thenReturn(1l);
    NicProfile nic = new NicProfile();
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    when(vm.getHostName()).thenReturn("UPPERCASENAME");
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(_datacenterDao.findById(zoneId)).thenReturn(mock(DataCenterVO.class));
    DeployDestination dest = new DeployDestination();
    ReservationContext context = new ReservationContextImpl(null, null, user);
    _globodnsElement.prepare(network, nic, vm, dest, context);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NicProfile(com.cloud.vm.NicProfile) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 10 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class InternalLoadBalancerElement method applyLBRules.

@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
    //1) Get Internal LB VMs to destroy
    Set<Ip> vmsToDestroy = getVmsToDestroy(network, rules);
    //2) Get rules to apply
    Map<Ip, List<LoadBalancingRule>> rulesToApply = getLbRulesToApply(rules);
    s_logger.debug("Applying " + rulesToApply.size() + " on element " + getName());
    for (Ip sourceIp : vmsToDestroy) {
        //2.1 Destroy internal lb vm
        List<? extends VirtualRouter> vms = _internalLbMgr.findInternalLbVms(network.getId(), sourceIp);
        if (vms.size() > 0) {
            //only one internal lb per IP exists
            try {
                s_logger.debug(String.format("Destroying internal lb vm for ip %s as all the rules for this vm are in Revoke state", sourceIp.addr()));
                return _internalLbMgr.destroyInternalLbVm(vms.get(0).getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), _accountMgr.getUserIncludingRemoved(User.UID_SYSTEM).getId());
            } catch (ConcurrentOperationException e) {
                s_logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e);
                return false;
            }
        }
        rulesToApply.remove(sourceIp);
    }
    for (Map.Entry<Ip, List<LoadBalancingRule>> entry : rulesToApply.entrySet()) {
        Ip sourceIp = entry.getKey();
        //2.2 Start Internal LB vm per IP address
        List<? extends VirtualRouter> internalLbVms;
        try {
            DeployDestination dest = new DeployDestination(_entityMgr.findById(DataCenter.class, network.getDataCenterId()), null, null, null);
            internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
        } catch (InsufficientCapacityException e) {
            s_logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e);
            return false;
        } catch (ConcurrentOperationException e) {
            s_logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e);
            return false;
        }
        if (internalLbVms == null || internalLbVms.isEmpty()) {
            throw new ResourceUnavailableException("Can't find/deploy internal lb vm to handle LB rules", DataCenter.class, network.getDataCenterId());
        }
        //2.3 Apply Internal LB rules on the VM
        if (!_internalLbMgr.applyLoadBalancingRules(network, entry.getValue(), internalLbVms)) {
            throw new CloudRuntimeException("Failed to apply load balancing rules for ip " + sourceIp.addr() + " in network " + network.getId() + " on element " + getName());
        }
    }
    return true;
}
Also used : Ip(com.cloud.utils.net.Ip) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) List(java.util.List) ArrayList(java.util.ArrayList) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DeployDestination (com.cloud.deploy.DeployDestination)56 DataCenter (com.cloud.dc.DataCenter)27 Account (com.cloud.user.Account)27 Test (org.junit.Test)27 ReservationContext (com.cloud.vm.ReservationContext)26 HostVO (com.cloud.host.HostVO)19 Network (com.cloud.network.Network)18 NetworkVO (com.cloud.network.dao.NetworkVO)18 NetworkOffering (com.cloud.offering.NetworkOffering)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 Domain (com.cloud.domain.Domain)17 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)15 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)15 URI (java.net.URI)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 ArrayList (java.util.ArrayList)11 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 Host (com.cloud.host.Host)8 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)8