VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, UserDataServiceProvider, SourceNatServiceProvider,
        StaticNatServiceProvider, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer,
        NetworkMigrationResponder, AggregatedCommandExecutor { @Override public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException, IllegalVirtualMachineException { if (vm.getType() != VirtualMachine.Type.User) { throw new IllegalVirtualMachineException("Illegal VM type informed. Expected USER VM, but got: " + vm.getType()); } if (!canHandle(network, null)) { return false; } final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); if (offering.isSystemOnly()) { return false; } if (!_networkMdl.isProviderEnabledInPhysicalNetwork(_networkMdl.getPhysicalNetworkId(network), getProvider().getName())) { return false; } final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create() .setGuestNetwork(network) .setDeployDestination(dest) .setAccountOwner(_accountMgr.getAccount(network.getAccountId())) .setParams(vm.getParameters()) .build(); final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter(); if (routers == null || routers.size() == 0) { throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId()); } return true; }  @Override boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context); @Override boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override boolean applyFWRules(final Network network, final List<? extends FirewallRule> rules); static boolean validateHAProxyLBRule(final LoadBalancingRule rule); @Override boolean validateLBRule(final Network network, final LoadBalancingRule rule); @Override boolean applyLBRules(final Network network, final List<LoadBalancingRule> rules); @Override String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users); @Override boolean startVpn(final RemoteAccessVpn vpn); @Override boolean stopVpn(final RemoteAccessVpn vpn); @Override boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Service> services); @Override Provider getProvider(); @Override Map<Service, Map<Capability, String>> getCapabilities(); static String getHAProxyStickinessCapability(); @Override boolean applyStaticNats(final Network network, final List<? extends StaticNat> rules); @Override boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup); @Override boolean destroy(final Network config, final ReservationContext context); @Override boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm); @Override boolean saveSSHKey(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final String sshPublicKey); @Override boolean saveUserData(final Network network, final NicProfile nic, final VirtualMachineProfile vm); @Override List<Class<?>> getCommands(); @Override VirtualRouterProvider configure(final ConfigureVirtualRouterElementCmd cmd); @Override VirtualRouterProvider addElement(final Long nspId, final Type providerType); @Override boolean applyPFRules(final Network network, final List<PortForwardingRule> rules); @Override boolean isReady(final PhysicalNetworkServiceProvider provider); @Override boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context); @Override boolean canEnableIndividualServices(); Long getIdByNspId(final Long nspId); @Override VirtualRouterProvider getCreatedElement(final long id); @Override boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context); @Override boolean configDhcpSupportForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest,
                                              final ReservationContext context); @Override boolean removeDhcpSupportForSubnet(final Network network); @Override boolean addDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest,
                                          final ReservationContext context); @Override List<? extends VirtualRouterProvider> searchForVirtualRouterElement(final ListVirtualRouterElementsCmd cmd); @Override boolean verifyServicesCombination(final Set<Service> services); @Override IpDeployer getIpDeployer(final Network network); @Override List<LoadBalancerTO> updateHealthChecks(final Network network, final List<LoadBalancingRule> lbrules); @Override boolean prepareMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override void rollbackMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst); @Override void commitMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst); @Override boolean prepareAggregatedExecution(final Network network, final DeployDestination dest); @Override boolean completeAggregatedExecution(final Network network, final DeployDestination dest); @Override boolean cleanupAggregatedExecution(final Network network, final DeployDestination dest); static final AutoScaleCounterType AutoScaleCounterCpu; static final AutoScaleCounterType AutoScaleCounterMemory; }
@Test @Ignore("Ignore it until it's fixed in order not to brake the build") public void testPrepare() { virtualRouterElement._routerMgr = _routerMgr; virtualRouterElement.routerDeploymentDefinitionBuilder = routerDeploymentDefinitionBuilder; mockDAOs(testNetwork, testOffering); mockMgrs(); boolean done = false; try { done = virtualRouterElement.prepare(testNetwork, testNicProfile, testVMProfile, testDestination, testContext); } catch (ConcurrentOperationException | InsufficientCapacityException | ResourceUnavailableException | IllegalVirtualMachineException e) { e.printStackTrace(); } assertTrue("can not even start to create a router", done); }