@Override
  public boolean generateFirewallConfiguration(Long ssAHostId) {
    if (ssAHostId == null) {
      return true;
    }
    HostVO ssAHost = _hostDao.findById(ssAHostId);
    Long zoneId = ssAHost.getDataCenterId();
    SecondaryStorageVmVO thisSecStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());

    if (thisSecStorageVm == null) {
      s_logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
      return false;
    }

    List<SecondaryStorageVmVO> alreadyRunning =
        _secStorageVmDao.getSecStorageVmListInStates(
            SecondaryStorageVm.Role.templateProcessor,
            State.Running,
            State.Migrating,
            State.Starting);

    String copyPort =
        _useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
    SecStorageFirewallCfgCommand cpc = new SecStorageFirewallCfgCommand();
    SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand();
    thiscpc.addPortConfig(
        thisSecStorageVm.getPublicIpAddress(),
        copyPort,
        true,
        TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
    for (SecondaryStorageVmVO ssVm : alreadyRunning) {
      if (ssVm.getDataCenterIdToDeployIn() == zoneId) {
        continue;
      }
      if (ssVm.getPublicIpAddress() != null) {
        cpc.addPortConfig(
            ssVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
      }
      if (ssVm.getState() != State.Running) {
        continue;
      }
      String instanceName = ssVm.getInstanceName();
      HostVO host = _hostDao.findByName(instanceName);
      if (host == null) {
        continue;
      }
      Answer answer = _agentMgr.easySend(host.getId(), thiscpc);
      if (answer != null && answer.getResult()) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("Successfully programmed firewall rules into " + ssVm.getHostName());
        }
      } else {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug(
              "failed to program firewall rules into secondary storage vm : " + ssVm.getHostName());
        }
        return false;
      }
    }

    Answer answer = _agentMgr.easySend(ssAHostId, cpc);
    if (answer != null && answer.getResult()) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(
            "Successfully programmed firewall rules into " + thisSecStorageVm.getHostName());
      }
    } else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(
            "failed to program firewall rules into secondary storage vm : "
                + thisSecStorageVm.getHostName());
      }
      return false;
    }

    return true;
  }
Example #2
0
  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");
    UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def");
    s_logger.info(
        "SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level");
    SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand();
    s_logger.info("GetHostStatsCommand should not show up at all in debug level");
    GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101);
    cmd2.addPortConfig("abc", "24", true, "eth0");
    cmd2.addPortConfig("127.0.0.1", "44", false, "eth1");
    Request sreq = new Request(2, 3, new Command[] {cmd1, cmd2, cmd3}, true, true);
    sreq.setSequence(892403717);

    Logger logger = Logger.getLogger(GsonHelper.class);
    Level level = logger.getLevel();

    logger.setLevel(Level.DEBUG);
    String log = sreq.log("Debug", true, Level.DEBUG);
    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, Level.TRACE);
    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, Level.INFO);
    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 (ClassNotFoundException e) {
      s_logger.error("Unable to parse bytes: ", e);
    } catch (UnsupportedVersionException e) {
      s_logger.error("Unable to parse bytes: ", e);
    }

    assert creq != null : "Couldn't get the request back";

    compareRequest(creq, sreq);

    Answer ans = new Answer(cmd1, true, "No Problem");
    Response cresp = new Response(creq, ans);

    bytes = cresp.getBytes();

    Response sresp = null;
    try {
      sresp = Response.parse(bytes);
    } catch (ClassNotFoundException e) {
      s_logger.error("Unable to parse bytes: ", e);
    } catch (UnsupportedVersionException e) {
      s_logger.error("Unable to parse bytes: ", e);
    }

    assert sresp != null : "Couldn't get the response back";

    compareRequest(cresp, sresp);
  }