Search in sources :

Example 1 with SecStorageFirewallCfgCommand

use of com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand in project cosmic by MissionCriticalCloud.

the class SecondaryStorageManagerImpl method generateFirewallConfiguration.

@Override
public boolean generateFirewallConfiguration(final Long ssAHostId) {
    if (ssAHostId == null) {
        return true;
    }
    final HostVO ssAHost = this._hostDao.findById(ssAHostId);
    final SecondaryStorageVmVO thisSecStorageVm = this._secStorageVmDao.findByInstanceName(ssAHost.getName());
    if (thisSecStorageVm == null) {
        logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
        return false;
    }
    final String copyPort = this._useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
    final SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
    thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
    final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
    sc.and(sc.entity().getType(), Op.EQ, HostType.SecondaryStorageVM);
    sc.and(sc.entity().getStatus(), Op.IN, HostStatus.Up, HostStatus.Connecting);
    final List<HostVO> ssvms = sc.list();
    for (final HostVO ssvm : ssvms) {
        if (ssvm.getId() == ssAHostId) {
            continue;
        }
        final Answer answer = this._agentMgr.easySend(ssvm.getId(), thiscpc);
        if (answer != null && answer.getResult()) {
            logger.debug("Successfully programmed firewall rules into SSVM " + ssvm.getName());
        } else {
            logger.debug("failed to program firewall rules into secondary storage vm : " + ssvm.getName());
            return false;
        }
    }
    final SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
    for (final HostVO ssvm : ssvms) {
        if (ssvm.getId() == ssAHostId) {
            continue;
        }
        allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
    }
    final Answer answer = this._agentMgr.easySend(ssAHostId, allSSVMIpList);
    if (answer != null && answer.getResult()) {
        logger.debug("Successfully programmed firewall rules into " + thisSecStorageVm.getHostName());
    } else {
        logger.debug("failed to program firewall rules into secondary storage vm : " + thisSecStorageVm.getHostName());
        return false;
    }
    return true;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) CheckSshAnswer(com.cloud.legacymodel.communication.answer.CheckSshAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) SecStorageFirewallCfgCommand(com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand) HostVO(com.cloud.host.HostVO)

Example 2 with SecStorageFirewallCfgCommand

use of com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand in project cosmic by MissionCriticalCloud.

the class RequestTest method testSerDeser.

@Test
@Ignore
public void testSerDeser() {
    s_logger.info("Testing serializing and deserializing works as expected");
    s_logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging");
    final UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def");
    s_logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level");
    final SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand();
    s_logger.info("GetHostStatsCommand should not show up at all in debug level");
    final GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101);
    cmd2.addPortConfig("abc", "24", true, "eth0");
    cmd2.addPortConfig("127.0.0.1", "44", false, "eth1");
    final Request sreq = new Request(2, 3, new Command[] { cmd1, cmd2, cmd3 }, true, true);
    sreq.setSequence(892403717);
    final Logger logger = LoggerFactory.getLogger(GsonHelper.class);
    // logger.setLevel(Level.DEBUG);
    String log = sreq.log("Debug", true);
    assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
    assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
    assert (!log.contains(GetHostStatsCommand.class.getSimpleName()));
    assert (!log.contains("username"));
    assert (!log.contains("password"));
    // logger.setLevel(Level.TRACE);
    log = sreq.log("Trace", true);
    assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName()));
    assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName()));
    assert (log.contains(GetHostStatsCommand.class.getSimpleName()));
    assert (!log.contains("username"));
    assert (!log.contains("password"));
    // logger.setLevel(Level.INFO);
    log = sreq.log("Info", true);
    assert (log == null);
    // logger.setLevel(level);
    byte[] bytes = sreq.getBytes();
    assert Request.getSequence(bytes) == 892403717;
    assert Request.getManagementServerId(bytes) == 3;
    assert Request.getAgentId(bytes) == 2;
    assert Request.getViaAgentId(bytes) == 2;
    Request creq = null;
    try {
        creq = Request.parse(bytes);
    } catch (final ClassNotFoundException e) {
        s_logger.error("Unable to parse bytes: ", e);
    } catch (final UnsupportedVersionException e) {
        s_logger.error("Unable to parse bytes: ", e);
    }
    assert creq != null : "Couldn't get the request back";
    compareRequest(creq, sreq);
    final Answer ans = new Answer(cmd1, true, "No Problem");
    final Response cresp = new Response(creq, ans);
    bytes = cresp.getBytes();
    Response sresp = null;
    try {
        sresp = Response.parse(bytes);
    } catch (final ClassNotFoundException e) {
        s_logger.error("Unable to parse bytes: ", e);
    } catch (final UnsupportedVersionException e) {
        s_logger.error("Unable to parse bytes: ", e);
    }
    assert sresp != null : "Couldn't get the response back";
    compareRequest(cresp, sresp);
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) UpdateHostPasswordCommand(com.cloud.legacymodel.communication.command.UpdateHostPasswordCommand) SecStorageFirewallCfgCommand(com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand) Logger(org.slf4j.Logger) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand) UnsupportedVersionException(com.cloud.legacymodel.exceptions.UnsupportedVersionException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)2 SecStorageFirewallCfgCommand (com.cloud.legacymodel.communication.command.SecStorageFirewallCfgCommand)2 HostVO (com.cloud.host.HostVO)1 CheckSshAnswer (com.cloud.legacymodel.communication.answer.CheckSshAnswer)1 SecStorageSetupAnswer (com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer)1 GetHostStatsCommand (com.cloud.legacymodel.communication.command.GetHostStatsCommand)1 UpdateHostPasswordCommand (com.cloud.legacymodel.communication.command.UpdateHostPasswordCommand)1 UnsupportedVersionException (com.cloud.legacymodel.exceptions.UnsupportedVersionException)1 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1