Search in sources :

Example 1 with CheckS2SVpnConnectionsCommand

use of com.cloud.agent.api.CheckS2SVpnConnectionsCommand in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method updateSite2SiteVpnConnectionState.

@DB
protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> routers) {
    for (final DomainRouterVO router : routers) {
        if (router.getRole() == Role.INTERNAL_LB_VM) {
            continue;
        }
        final List<Site2SiteVpnConnectionVO> conns = _s2sVpnMgr.getConnectionsForRouter(router);
        if (conns == null || conns.isEmpty()) {
            continue;
        }
        if (router.getIsRedundantRouter() && router.getRedundantState() != RedundantState.PRIMARY) {
            continue;
        }
        if (router.getState() != VirtualMachine.State.Running) {
            for (final Site2SiteVpnConnectionVO conn : conns) {
                if (conn.getState() != Site2SiteVpnConnection.State.Error) {
                    conn.setState(Site2SiteVpnConnection.State.Disconnected);
                    _s2sVpnConnectionDao.persist(conn);
                }
            }
            continue;
        }
        final List<String> ipList = new ArrayList<String>();
        for (final Site2SiteVpnConnectionVO conn : conns) {
            if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected && conn.getState() != Site2SiteVpnConnection.State.Connecting) {
                continue;
            }
            final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
            ipList.add(gw.getGatewayIp());
        }
        final String privateIP = router.getPrivateIpAddress();
        final HostVO host = _hostDao.findById(router.getHostId());
        if (host == null || host.getState() != Status.Up) {
            continue;
        } else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
            /* Only cover hosts managed by this management server */
            continue;
        } else if (privateIP != null) {
            final CheckS2SVpnConnectionsCommand command = new CheckS2SVpnConnectionsCommand(ipList);
            command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
            command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
            command.setWait(30);
            final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
            CheckS2SVpnConnectionsAnswer answer = null;
            if (origAnswer instanceof CheckS2SVpnConnectionsAnswer) {
                answer = (CheckS2SVpnConnectionsAnswer) origAnswer;
            } else {
                s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
                continue;
            }
            if (!answer.getResult()) {
                s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
                continue;
            }
            for (final Site2SiteVpnConnectionVO conn : conns) {
                final Site2SiteVpnConnectionVO lock = _s2sVpnConnectionDao.acquireInLockTable(conn.getId());
                if (lock == null) {
                    throw new CloudRuntimeException("Unable to acquire lock for site to site vpn connection id " + conn.getId());
                }
                try {
                    if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected && conn.getState() != Site2SiteVpnConnection.State.Connecting) {
                        continue;
                    }
                    final Site2SiteVpnConnection.State oldState = conn.getState();
                    final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
                    if (answer.isIPPresent(gw.getGatewayIp())) {
                        if (answer.isConnected(gw.getGatewayIp())) {
                            conn.setState(Site2SiteVpnConnection.State.Connected);
                        } else {
                            conn.setState(Site2SiteVpnConnection.State.Disconnected);
                        }
                        _s2sVpnConnectionDao.persist(conn);
                        if (oldState != conn.getState()) {
                            final String title = "Site-to-site Vpn Connection to " + gw.getName() + " just switched from " + oldState + " to " + conn.getState();
                            final String context = "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() + "(id: " + router.getId() + ") " + " just switched from " + oldState + " to " + conn.getState();
                            s_logger.info(context);
                            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
                        }
                    }
                } finally {
                    _s2sVpnConnectionDao.releaseFromLockTable(lock.getId());
                }
            }
        }
    }
}
Also used : CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) ArrayList(java.util.ArrayList) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) DB(com.cloud.utils.db.DB)

Example 2 with CheckS2SVpnConnectionsCommand

use of com.cloud.agent.api.CheckS2SVpnConnectionsCommand in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImplTest method testUpdateSite2SiteVpnConnectionState.

@Test
public void testUpdateSite2SiteVpnConnectionState() throws Exception {
    DomainRouterVO router = new DomainRouterVO(1L, 1L, 1L, "First testing router", 1L, Hypervisor.HypervisorType.XenServer, 1L, 1L, 1L, 1L, false, VirtualRouter.RedundantState.PRIMARY, true, true, 1L);
    router.setState(VirtualMachine.State.Running);
    router.setPrivateIpAddress("192.168.50.15");
    List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
    routers.add(router);
    Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(1L, 1L, 1L, 1L, false);
    Site2SiteVpnConnectionVO conn1 = new Site2SiteVpnConnectionVO(1L, 1L, 1L, 1L, false);
    conn.setState(Site2SiteVpnConnection.State.Disconnected);
    conn1.setState(Site2SiteVpnConnection.State.Disconnected);
    List<Site2SiteVpnConnectionVO> conns = new ArrayList<Site2SiteVpnConnectionVO>();
    conns.add(conn);
    conns.add(conn1);
    Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO("Testing gateway", 1L, 1L, "192.168.50.15", "Guest List", "ipsecPsk", "ikePolicy", "espPolicy", 1L, 1L, true, true, false, "ike");
    HostVO hostVo = new HostVO(1L, "Testing host", Host.Type.Routing, "192.168.50.15", "privateNetmask", "privateMacAddress", "publicIpAddress", "publicNetmask", "publicMacAddress", "storageIpAddress", "storageNetmask", "storageMacAddress", "deuxStorageIpAddress", "duxStorageNetmask", "deuxStorageMacAddress", "guid", Status.Up, "version", "iqn", new Date(), 1L, 1L, 1L, 1L, "parent", 20L, Storage.StoragePoolType.Gluster);
    hostVo.setManagementServerId(ManagementServerNode.getManagementServerId());
    ArrayList<String> ipList = new ArrayList<>();
    ipList.add("192.168.50.15");
    _s2sConnCommand = new CheckS2SVpnConnectionsCommand(ipList);
    when(_s2sVpnMgr.getConnectionsForRouter(router)).thenReturn(conns);
    when(_s2sVpnConnectionDao.persist(conn)).thenReturn(null);
    when(_s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId())).thenReturn(gw);
    when(_hostDao.findById(router.getHostId())).thenReturn(hostVo);
    when(_routerControlHelper.getRouterControlIp(router.getId())).thenReturn("192.168.50.15");
    doReturn(_s2sVpnAnswer).when(_agentMgr).easySend(nullable(Long.class), nullable(CheckS2SVpnConnectionsCommand.class));
    when(_s2sVpnAnswer.getResult()).thenReturn(true);
    when(_s2sVpnConnectionDao.acquireInLockTable(conn.getId())).thenReturn(conn);
    when(_s2sVpnAnswer.isIPPresent("192.168.50.15")).thenReturn(true);
    when(_s2sVpnAnswer.isConnected("192.168.50.15")).thenReturn(true);
    lenient().doNothing().when(_alertMgr).sendAlert(any(AlertManager.AlertType.class), anyLong(), anyLong(), anyString(), anyString());
    virtualNetworkApplianceManagerImpl.updateSite2SiteVpnConnectionState(routers);
    for (Site2SiteVpnConnection connection : conns) {
        assertEquals(Site2SiteVpnConnection.State.Connected, connection.getState());
    }
}
Also used : Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) HostVO(com.cloud.host.HostVO) Date(java.util.Date) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) Matchers.anyLong(org.mockito.Matchers.anyLong) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 3 with CheckS2SVpnConnectionsCommand

use of com.cloud.agent.api.CheckS2SVpnConnectionsCommand in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method updateSite2SiteVpnConnectionState.

@DB
protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> routers) {
    for (final DomainRouterVO router : routers) {
        final List<Site2SiteVpnConnectionVO> conns = _s2sVpnMgr.getConnectionsForRouter(router);
        if (conns == null || conns.isEmpty()) {
            continue;
        }
        if (router.getIsRedundantRouter() && router.getRedundantState() != RedundantState.MASTER) {
            continue;
        }
        if (router.getState() != VirtualMachine.State.Running) {
            for (final Site2SiteVpnConnectionVO conn : conns) {
                if (conn.getState() != Site2SiteVpnConnection.State.Error) {
                    conn.setState(Site2SiteVpnConnection.State.Disconnected);
                    _s2sVpnConnectionDao.persist(conn);
                }
            }
            continue;
        }
        final List<String> ipList = new ArrayList<>();
        for (final Site2SiteVpnConnectionVO conn : conns) {
            if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
                continue;
            }
            final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
            ipList.add(gw.getGatewayIp());
        }
        final String privateIP = router.getPrivateIpAddress();
        final HostVO host = _hostDao.findById(router.getHostId());
        if (host == null || host.getState() != Status.Up) {
            continue;
        } else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
            /* Only cover hosts managed by this management server */
            continue;
        } else if (privateIP != null) {
            final CheckS2SVpnConnectionsCommand command = new CheckS2SVpnConnectionsCommand(ipList);
            command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
            command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
            command.setWait(30);
            final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
            CheckS2SVpnConnectionsAnswer answer = null;
            if (origAnswer instanceof CheckS2SVpnConnectionsAnswer) {
                answer = (CheckS2SVpnConnectionsAnswer) origAnswer;
            } else {
                s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
                continue;
            }
            if (!answer.getResult()) {
                s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
                continue;
            }
            for (final Site2SiteVpnConnectionVO conn : conns) {
                final Site2SiteVpnConnectionVO lock = _s2sVpnConnectionDao.acquireInLockTable(conn.getId());
                if (lock == null) {
                    throw new CloudRuntimeException("Unable to acquire lock for site to site vpn connection id " + conn.getId());
                }
                try {
                    if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
                        continue;
                    }
                    final Site2SiteVpnConnection.State oldState = conn.getState();
                    final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
                    if (answer.isIpPresent(gw.getGatewayIp())) {
                        if (answer.isConnected(gw.getGatewayIp())) {
                            conn.setState(Site2SiteVpnConnection.State.Connected);
                        } else {
                            conn.setState(Site2SiteVpnConnection.State.Disconnected);
                        }
                        _s2sVpnConnectionDao.persist(conn);
                        if (oldState != conn.getState()) {
                            final String title = "Site-to-site Vpn Connection to " + gw.getName() + " just switch from " + oldState + " to " + conn.getState();
                            final String context = "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() + "(id: " + router.getId() + ") " + " just switch from " + oldState + " to " + conn.getState();
                            s_logger.info(context);
                            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
                        }
                    }
                } finally {
                    _s2sVpnConnectionDao.releaseFromLockTable(lock.getId());
                }
            }
        }
    }
}
Also used : CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) ArrayList(java.util.ArrayList) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) DB(com.cloud.utils.db.DB)

Example 4 with CheckS2SVpnConnectionsCommand

use of com.cloud.agent.api.CheckS2SVpnConnectionsCommand in project cloudstack by apache.

the class SimulatorManagerImpl method simulate.

@DB
@Override
public Answer simulate(final Command cmd, final String hostGuid) {
    s_logger.debug("Simulate command " + cmd);
    Answer answer = null;
    Exception exception = null;
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        final MockHost host = _mockHost.findByGuid(hostGuid);
        String cmdName = cmd.toString();
        final int index = cmdName.lastIndexOf(".");
        if (index != -1) {
            cmdName = cmdName.substring(index + 1);
        }
        final SimulatorInfo info = new SimulatorInfo();
        info.setHostUuid(hostGuid);
        final MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);
        if (config != null && (config.getCount() == null || config.getCount().intValue() > 0)) {
            final Map<String, String> configParameters = config.getParameters();
            for (final Map.Entry<String, String> entry : configParameters.entrySet()) {
                if (entry.getKey().equalsIgnoreCase("enabled")) {
                    info.setEnabled(Boolean.parseBoolean(entry.getValue()));
                } else if (entry.getKey().equalsIgnoreCase("timeout")) {
                    try {
                        info.setTimeout(Integer.valueOf(entry.getValue()));
                    } catch (final NumberFormatException e) {
                        s_logger.debug("invalid timeout parameter: " + e.toString());
                    }
                }
                if (entry.getKey().equalsIgnoreCase("wait")) {
                    try {
                        final int wait = Integer.valueOf(entry.getValue());
                        Thread.sleep(wait);
                    } catch (final NumberFormatException e) {
                        s_logger.debug("invalid wait parameter: " + e.toString());
                    } catch (final InterruptedException e) {
                        s_logger.debug("thread is interrupted: " + e.toString());
                    }
                }
                if (entry.getKey().equalsIgnoreCase("result")) {
                    final String value = entry.getValue();
                    if (value.equalsIgnoreCase("fail")) {
                        answer = new Answer(cmd, false, "Simulated failure");
                    } else if (value.equalsIgnoreCase("fault")) {
                        exception = new Exception("Simulated fault");
                    }
                }
            }
            if (exception != null) {
                throw exception;
            }
            if (answer == null) {
                final String message = config.getJsonResponse();
                if (message != null) {
                    // json response looks like {"<Type>":....}
                    final String objectType = message.split(":")[0].substring(2).replace("\"", "");
                    final String objectData = message.substring(message.indexOf(':') + 1, message.length() - 1);
                    if (objectType != null) {
                        Class<?> clz = null;
                        try {
                            clz = Class.forName(objectType);
                        } catch (final ClassNotFoundException e) {
                        }
                        if (clz != null) {
                            final StringReader reader = new StringReader(objectData);
                            final JsonReader jsonReader = new JsonReader(reader);
                            jsonReader.setLenient(true);
                            answer = (Answer) s_gson.fromJson(jsonReader, clz);
                        }
                    }
                }
            }
        }
        if (answer == null) {
            if (cmd instanceof GetHostStatsCommand) {
                answer = _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
            } else if (cmd instanceof CheckHealthCommand) {
                answer = _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
            } else if (cmd instanceof PingTestCommand) {
                answer = _mockAgentMgr.pingTest((PingTestCommand) cmd);
            } else if (cmd instanceof SetupKeyStoreCommand) {
                answer = _mockAgentMgr.setupKeyStore((SetupKeyStoreCommand) cmd);
            } else if (cmd instanceof DiagnosticsCommand) {
                answer = _mockAgentMgr.runDiagnostics((DiagnosticsCommand) cmd);
            } else if (cmd instanceof SetupCertificateCommand) {
                answer = _mockAgentMgr.setupCertificate((SetupCertificateCommand) cmd);
            } else if (cmd instanceof PrepareForMigrationCommand) {
                answer = _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
            } else if (cmd instanceof MigrateCommand) {
                answer = _mockVmMgr.migrate((MigrateCommand) cmd, info);
            } else if (cmd instanceof StartCommand) {
                answer = _mockVmMgr.startVM((StartCommand) cmd, info);
            } else if (cmd instanceof CheckSshCommand) {
                answer = _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
            } else if (cmd instanceof CheckVirtualMachineCommand) {
                answer = _mockVmMgr.checkVmState((CheckVirtualMachineCommand) cmd);
            } else if (cmd instanceof SetStaticNatRulesCommand) {
                answer = _mockNetworkMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
            } else if (cmd instanceof SetFirewallRulesCommand) {
                answer = _mockNetworkMgr.SetFirewallRules((SetFirewallRulesCommand) cmd);
            } else if (cmd instanceof SetPortForwardingRulesCommand) {
                answer = _mockNetworkMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
            } else if (cmd instanceof NetworkUsageCommand) {
                answer = _mockNetworkMgr.getNetworkUsage((NetworkUsageCommand) cmd);
            } else if (cmd instanceof IpAssocCommand) {
                answer = _mockNetworkMgr.IpAssoc((IpAssocCommand) cmd);
            } else if (cmd instanceof LoadBalancerConfigCommand) {
                answer = _mockNetworkMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
            } else if (cmd instanceof DhcpEntryCommand) {
                answer = _mockNetworkMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
            } else if (cmd instanceof VmDataCommand) {
                answer = _mockVmMgr.setVmData((VmDataCommand) cmd);
            } else if (cmd instanceof CleanupNetworkRulesCmd) {
                answer = _mockVmMgr.cleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
            } else if (cmd instanceof CheckNetworkCommand) {
                answer = _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
            } else if (cmd instanceof StopCommand) {
                answer = _mockVmMgr.stopVM((StopCommand) cmd);
            } else if (cmd instanceof RebootCommand) {
                answer = _mockVmMgr.rebootVM((RebootCommand) cmd);
            } else if (cmd instanceof GetVncPortCommand) {
                answer = _mockVmMgr.getVncPort((GetVncPortCommand) cmd);
            } else if (cmd instanceof CheckConsoleProxyLoadCommand) {
                answer = _mockVmMgr.checkConsoleProxyLoad((CheckConsoleProxyLoadCommand) cmd);
            } else if (cmd instanceof WatchConsoleProxyLoadCommand) {
                answer = _mockVmMgr.watchConsoleProxyLoad((WatchConsoleProxyLoadCommand) cmd);
            } else if (cmd instanceof SecurityGroupRulesCmd) {
                answer = _mockVmMgr.addSecurityGroupRules((SecurityGroupRulesCmd) cmd, info);
            } else if (cmd instanceof SavePasswordCommand) {
                answer = _mockVmMgr.savePassword((SavePasswordCommand) cmd);
            } else if (cmd instanceof PrimaryStorageDownloadCommand) {
                answer = _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand) cmd);
            } else if (cmd instanceof CreateCommand) {
                answer = _mockStorageMgr.createVolume((CreateCommand) cmd);
            } else if (cmd instanceof AttachIsoCommand) {
                answer = _mockStorageMgr.AttachIso((AttachIsoCommand) cmd);
            } else if (cmd instanceof DeleteStoragePoolCommand) {
                answer = _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand) cmd);
            } else if (cmd instanceof ModifyStoragePoolCommand) {
                answer = _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand) cmd);
            } else if (cmd instanceof CreateStoragePoolCommand) {
                answer = _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand) cmd);
            } else if (cmd instanceof SecStorageSetupCommand) {
                answer = _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand) cmd);
            } else if (cmd instanceof ListTemplateCommand) {
                answer = _mockStorageMgr.ListTemplates((ListTemplateCommand) cmd);
            } else if (cmd instanceof ListVolumeCommand) {
                answer = _mockStorageMgr.ListVolumes((ListVolumeCommand) cmd);
            } else if (cmd instanceof DestroyCommand) {
                answer = _mockStorageMgr.Destroy((DestroyCommand) cmd);
            } else if (cmd instanceof DownloadProgressCommand) {
                answer = _mockStorageMgr.DownloadProcess((DownloadProgressCommand) cmd);
            } else if (cmd instanceof DownloadCommand) {
                answer = _mockStorageMgr.Download((DownloadCommand) cmd);
            } else if (cmd instanceof GetStorageStatsCommand) {
                answer = _mockStorageMgr.GetStorageStats((GetStorageStatsCommand) cmd);
            } else if (cmd instanceof GetVolumeStatsCommand) {
                answer = _mockStorageMgr.getVolumeStats((GetVolumeStatsCommand) cmd);
            } else if (cmd instanceof ManageSnapshotCommand) {
                answer = _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand) cmd);
            } else if (cmd instanceof BackupSnapshotCommand) {
                answer = _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand) cmd, info);
            } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
                answer = _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand) cmd);
            } else if (cmd instanceof DeleteCommand) {
                answer = _mockStorageMgr.Delete((DeleteCommand) cmd);
            } else if (cmd instanceof SecStorageVMSetupCommand) {
                answer = _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand) cmd);
            } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
                answer = _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand) cmd);
            } else if (cmd instanceof ComputeChecksumCommand) {
                answer = _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand) cmd);
            } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
                answer = _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand) cmd);
            } else if (cmd instanceof UploadStatusCommand) {
                answer = _mockStorageMgr.getUploadStatus((UploadStatusCommand) cmd);
            } else if (cmd instanceof MaintainCommand) {
                answer = _mockAgentMgr.maintain((MaintainCommand) cmd);
            } else if (cmd instanceof GetVmStatsCommand) {
                answer = _mockVmMgr.getVmStats((GetVmStatsCommand) cmd);
            } else if (cmd instanceof CheckRouterCommand) {
                answer = _mockVmMgr.checkRouter((CheckRouterCommand) cmd);
            } else if (cmd instanceof GetDomRVersionCmd) {
                answer = _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
            } else if (cmd instanceof CopyVolumeCommand) {
                answer = _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
            } else if (cmd instanceof PlugNicCommand) {
                answer = _mockNetworkMgr.plugNic((PlugNicCommand) cmd);
            } else if (cmd instanceof UnPlugNicCommand) {
                answer = _mockNetworkMgr.unplugNic((UnPlugNicCommand) cmd);
            } else if (cmd instanceof ReplugNicCommand) {
                answer = _mockNetworkMgr.replugNic((ReplugNicCommand) cmd);
            } else if (cmd instanceof IpAssocVpcCommand) {
                answer = _mockNetworkMgr.ipAssoc((IpAssocVpcCommand) cmd);
            } else if (cmd instanceof SetSourceNatCommand) {
                answer = _mockNetworkMgr.setSourceNat((SetSourceNatCommand) cmd);
            } else if (cmd instanceof SetNetworkACLCommand) {
                answer = _mockNetworkMgr.setNetworkAcl((SetNetworkACLCommand) cmd);
            } else if (cmd instanceof SetupGuestNetworkCommand) {
                answer = _mockNetworkMgr.setUpGuestNetwork((SetupGuestNetworkCommand) cmd);
            } else if (cmd instanceof SetPortForwardingRulesVpcCommand) {
                answer = _mockNetworkMgr.setVpcPortForwards((SetPortForwardingRulesVpcCommand) cmd);
            } else if (cmd instanceof SetStaticNatRulesCommand) {
                answer = _mockNetworkMgr.setVPCStaticNatRules((SetStaticNatRulesCommand) cmd);
            } else if (cmd instanceof SetStaticRouteCommand) {
                answer = _mockNetworkMgr.setStaticRoute((SetStaticRouteCommand) cmd);
            } else if (cmd instanceof Site2SiteVpnCfgCommand) {
                answer = _mockNetworkMgr.siteToSiteVpn((Site2SiteVpnCfgCommand) cmd);
            } else if (cmd instanceof CheckS2SVpnConnectionsCommand) {
                answer = _mockNetworkMgr.checkSiteToSiteVpnConnection((CheckS2SVpnConnectionsCommand) cmd);
            } else if (cmd instanceof CreateVMSnapshotCommand) {
                answer = _mockVmMgr.createVmSnapshot((CreateVMSnapshotCommand) cmd);
            } else if (cmd instanceof DeleteVMSnapshotCommand) {
                answer = _mockVmMgr.deleteVmSnapshot((DeleteVMSnapshotCommand) cmd);
            } else if (cmd instanceof RevertToVMSnapshotCommand) {
                answer = _mockVmMgr.revertVmSnapshot((RevertToVMSnapshotCommand) cmd);
            } else if (cmd instanceof NetworkRulesVmSecondaryIpCommand) {
                answer = _mockVmMgr.plugSecondaryIp((NetworkRulesVmSecondaryIpCommand) cmd);
            } else if (cmd instanceof ScaleVmCommand) {
                answer = _mockVmMgr.scaleVm((ScaleVmCommand) cmd);
            } else if (cmd instanceof PvlanSetupCommand) {
                answer = _mockNetworkMgr.setupPVLAN((PvlanSetupCommand) cmd);
            } else if (cmd instanceof StorageSubSystemCommand) {
                answer = storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
            } else if (cmd instanceof FenceCommand) {
                answer = _mockVmMgr.fence((FenceCommand) cmd);
            } else if (cmd instanceof HandleConfigDriveIsoCommand) {
                answer = _mockStorageMgr.handleConfigDriveIso((HandleConfigDriveIsoCommand) cmd);
            } else if (cmd instanceof GetRouterAlertsCommand || cmd instanceof VpnUsersCfgCommand || cmd instanceof RemoteAccessVpnCfgCommand || cmd instanceof SetMonitorServiceCommand || cmd instanceof AggregationControlCommand || cmd instanceof SecStorageFirewallCfgCommand) {
                answer = new Answer(cmd);
            } else {
                s_logger.error("Simulator does not implement command of type " + cmd.toString());
                answer = Answer.createUnsupportedCommandAnswer(cmd);
            }
        }
        if (config != null && config.getCount() != null && config.getCount().intValue() > 0) {
            if (answer != null) {
                config.setCount(config.getCount().intValue() - 1);
                _mockConfigDao.update(config.getId(), config);
            }
        }
        s_logger.debug("Finished simulate command " + cmd);
        return answer;
    } catch (final Exception e) {
        s_logger.error("Failed execute cmd: ", e);
        txn.rollback();
        return new Answer(cmd, false, e.toString());
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : DiagnosticsCommand(org.apache.cloudstack.diagnostics.DiagnosticsCommand) VpnUsersCfgCommand(com.cloud.agent.api.routing.VpnUsersCfgCommand) GetRouterAlertsCommand(com.cloud.agent.api.routing.GetRouterAlertsCommand) Site2SiteVpnCfgCommand(com.cloud.agent.api.routing.Site2SiteVpnCfgCommand) GetDomRVersionCmd(com.cloud.agent.api.GetDomRVersionCmd) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) HandleConfigDriveIsoCommand(com.cloud.agent.api.HandleConfigDriveIsoCommand) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) ComputeChecksumCommand(com.cloud.agent.api.ComputeChecksumCommand) MigrateCommand(com.cloud.agent.api.MigrateCommand) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) UploadStatusCommand(org.apache.cloudstack.storage.command.UploadStatusCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) DeleteVMSnapshotCommand(com.cloud.agent.api.DeleteVMSnapshotCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) SecStorageVMSetupCommand(com.cloud.agent.api.SecStorageVMSetupCommand) SetupKeyStoreCommand(org.apache.cloudstack.ca.SetupKeyStoreCommand) Map(java.util.Map) HashMap(java.util.HashMap) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) RevertToVMSnapshotCommand(com.cloud.agent.api.RevertToVMSnapshotCommand) CheckConsoleProxyLoadCommand(com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) NetworkRulesVmSecondaryIpCommand(com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) WatchConsoleProxyLoadCommand(com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand) CreateVMSnapshotCommand(com.cloud.agent.api.CreateVMSnapshotCommand) ReplugNicCommand(com.cloud.agent.api.ReplugNicCommand) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) StringReader(java.io.StringReader) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) SetNetworkACLCommand(com.cloud.agent.api.routing.SetNetworkACLCommand) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) FenceCommand(com.cloud.agent.api.FenceCommand) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) RemoteAccessVpnCfgCommand(com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) SetMonitorServiceCommand(com.cloud.agent.api.routing.SetMonitorServiceCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) GetVolumeStatsCommand(com.cloud.agent.api.GetVolumeStatsCommand) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) CreateCommand(com.cloud.agent.api.storage.CreateCommand) SetStaticRouteCommand(com.cloud.agent.api.routing.SetStaticRouteCommand) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) SecStorageFirewallCfgCommand(com.cloud.agent.api.SecStorageFirewallCfgCommand) IpAssocVpcCommand(com.cloud.agent.api.routing.IpAssocVpcCommand) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand) CleanupNetworkRulesCmd(com.cloud.agent.api.CleanupNetworkRulesCmd) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) SetupCertificateCommand(org.apache.cloudstack.ca.SetupCertificateCommand) StopCommand(com.cloud.agent.api.StopCommand) PrepareForMigrationCommand(com.cloud.agent.api.PrepareForMigrationCommand) MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) RebootCommand(com.cloud.agent.api.RebootCommand) StartCommand(com.cloud.agent.api.StartCommand) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) JsonReader(com.google.gson.stream.JsonReader) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) DownloadProgressCommand(org.apache.cloudstack.storage.command.DownloadProgressCommand) Answer(com.cloud.agent.api.Answer) ListVolumeCommand(com.cloud.agent.api.storage.ListVolumeCommand) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) MockHost(com.cloud.simulator.MockHost) CreateStoragePoolCommand(com.cloud.agent.api.CreateStoragePoolCommand) DB(com.cloud.utils.db.DB)

Aggregations

CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)4 Answer (com.cloud.agent.api.Answer)3 DB (com.cloud.utils.db.DB)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)2 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)2 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)2 HostVO (com.cloud.host.HostVO)2 Site2SiteVpnConnection (com.cloud.network.Site2SiteVpnConnection)2 Site2SiteVpnConnectionVO (com.cloud.network.dao.Site2SiteVpnConnectionVO)2 DomainRouterVO (com.cloud.vm.DomainRouterVO)2 ArrayList (java.util.ArrayList)2 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)1 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)1 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)1 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)1