protected VDS getEntity(int index) {
   VDS vds = setUpEntityExpectations(control.createMock(VDS.class), index);
   VdsStatic vdsStatic = control.createMock(VdsStatic.class);
   expect(vdsStatic.getId()).andReturn(GUIDS[2]).anyTimes();
   expect(vds.getStaticData()).andReturn(vdsStatic).anyTimes();
   return vds;
 }
Exemplo n.º 2
0
  /** Ensures that the right object is returned. */
  @Test
  public void testGet() {
    VdsDynamic result = dao.get(existingVds.getId());

    assertNotNull(result);
    assertEquals(existingVds.getId(), result.getId());
  }
Exemplo n.º 3
0
 @Test
 public void testUpdateStatus() {
   VdsDynamic before = dao.get(existingVds.getId());
   before.setStatus(VDSStatus.Down);
   dao.updateStatus(before.getId(), before.getStatus());
   VdsDynamic after = dao.get(existingVds.getId());
   assertEquals(before, after);
 }
Exemplo n.º 4
0
 @Test
 public void testUpdateHostExternalStatus() {
   VdsDynamic before = dao.get(existingVds.getId());
   before.setExternalStatus(ExternalStatus.Error);
   dao.updateExternalStatus(before.getId(), before.getExternalStatus());
   VdsDynamic after = dao.get(existingVds.getId());
   assertEquals(before.getExternalStatus(), after.getExternalStatus());
 }
Exemplo n.º 5
0
 @Test
 public void testUpdateAvailableUpdates() {
   VdsDynamic before = dao.get(existingVds.getId());
   assertFalse(before.isUpdateAvailable());
   before.setUpdateAvailable(true);
   dao.updateUpdateAvailable(before.getId(), before.isUpdateAvailable());
   VdsDynamic after = dao.get(existingVds.getId());
   assertEquals(before.isUpdateAvailable(), after.isUpdateAvailable());
 }
Exemplo n.º 6
0
 @Test
 public void testGlusterVersion() {
   RpmVersion glusterVersion = new RpmVersion("glusterfs-3.4.0.34.1u2rhs-1.el6rhs");
   VdsDynamic before = dao.get(existingVds.getId());
   before.setGlusterVersion(glusterVersion);
   dao.update(before);
   VdsDynamic after = dao.get(existingVds.getId());
   assertEquals(glusterVersion, after.getGlusterVersion());
 }
Exemplo n.º 7
0
 @Test
 public void testUpdateNetConfigDirty() {
   VdsDynamic before = dao.get(existingVds.getId());
   Boolean netConfigDirty = before.getNetConfigDirty();
   netConfigDirty = Boolean.FALSE.equals(netConfigDirty);
   before.setNetConfigDirty(netConfigDirty);
   dao.updateNetConfigDirty(before.getId(), netConfigDirty);
   VdsDynamic after = dao.get(existingVds.getId());
   assertEquals(before, after);
 }
Exemplo n.º 8
0
 @Test
 public void testUpdateLibrbdVersion() {
   RpmVersion librbdVersion = new RpmVersion("librbd1-0.80.9-1.fc21.x86_64_updated");
   VdsDynamic before = dao.get(existingVds.getId());
   assertNotEquals(librbdVersion, before.getLibrbdVersion());
   before.setLibrbdVersion(librbdVersion);
   dao.update(before);
   VdsDynamic after = dao.get(existingVds.getId());
   assertEquals(librbdVersion, after.getLibrbdVersion());
 }
 @Override
 public void save(VdsStatic vds) {
   Guid id = vds.getId();
   if (Guid.isNullOrEmpty(id)) {
     id = Guid.newGuid();
     vds.setId(id);
   }
   new SimpleJdbcCall(jdbcTemplate)
       .withProcedureName("InsertVdsStatic")
       .execute(getInsertOrUpdateParams(vds));
 }
Exemplo n.º 10
0
 private void checkKdumpIntegrationStatus() {
   VdsStatic vdsSt = getParameters().getVdsStaticData();
   if (vdsSt.isPmEnabled() && vdsSt.isPmKdumpDetection()) {
     VdsDynamic vdsDyn = getDbFacade().getVdsDynamicDao().get(vdsSt.getId());
     if (vdsDyn != null && vdsDyn.getKdumpStatus() != KdumpStatus.ENABLED) {
       auditLogDirector.log(
           new AuditLogableBase(vdsSt.getId()),
           AuditLogType.KDUMP_DETECTION_NOT_CONFIGURED_ON_VDS);
     }
   }
 }
Exemplo n.º 11
0
  /** Ensures removing a VDS instance works. */
  @Test
  public void testRemove() {
    dao.remove(existingVds.getId());
    statisticsDao.remove(existingVds.getId());
    staticDao.remove(existingVds.getId());

    VdsStatic resultStatic = staticDao.get(existingVds.getId());
    assertNull(resultStatic);
    VdsDynamic resultDynamic = dao.get(existingVds.getId());
    assertNull(resultDynamic);
  }
Exemplo n.º 12
0
 @Test
 public void testUpdateStatusAndReasons() {
   VdsDynamic before = dao.get(existingVds.getId());
   before.setStatus(RandomUtils.instance().nextEnum(VDSStatus.class));
   before.setNonOperationalReason(RandomUtils.instance().nextEnum(NonOperationalReason.class));
   before.setMaintenanceReason(RandomUtils.instance().nextString(50));
   dao.updateStatusAndReasons(before);
   VdsDynamic after = dao.get(existingVds.getId());
   assertEquals(before, after);
   assertEquals(before.getStatus(), after.getStatus());
   assertEquals(before.getNonOperationalReason(), after.getNonOperationalReason());
   assertEquals(before.getMaintenanceReason(), after.getMaintenanceReason());
 }
Exemplo n.º 13
0
  @Override
  public void setUp() throws Exception {
    super.setUp();

    dao = dbFacade.getVdsDynamicDao();
    staticDao = dbFacade.getVdsStaticDao();
    statisticsDao = dbFacade.getVdsStatisticsDao();
    existingVds = staticDao.get(FixturesTool.VDS_GLUSTER_SERVER2);

    newStaticVds = new VdsStatic();
    newStaticVds.setHostName("farkle.redhat.com");
    newStaticVds.setVdsGroupId(existingVds.getVdsGroupId());
    newStaticVds.setProtocol(VdsProtocol.STOMP);
    newDynamicVds = new VdsDynamic();
  }
Exemplo n.º 14
0
  protected T getMethod() {
    if (method == null) {
      VdsStatic vdsStatic = getAndSetVdsStatic();

      Pair<String, URL> urlInfo =
          XmlRpcUtils.getConnectionUrl(
              vdsStatic.getHostName(),
              vdsStatic.getPort(),
              "",
              Config.<Boolean>getValue(ConfigValues.EncryptHostCommunication));

      method = concreteCreateMethod(urlInfo.getFirst());
    }

    return method;
  }
Exemplo n.º 15
0
  /** Ensures saving a VDS instance works. */
  @Test
  public void testSave() {
    staticDao.save(newStaticVds);
    newDynamicVds.setId(newStaticVds.getId());
    newDynamicVds.setUpdateAvailable(true);
    dao.save(newDynamicVds);

    VdsStatic staticResult = staticDao.get(newStaticVds.getId());
    VdsDynamic dynamicResult = dao.get(newDynamicVds.getId());

    assertNotNull(staticResult);
    assertEquals(newStaticVds, staticResult);
    assertNotNull(dynamicResult);
    assertEquals(newDynamicVds, dynamicResult);
    assertEquals(newDynamicVds.isUpdateAvailable(), dynamicResult.isUpdateAvailable());
  }
  @Test
  public void testGetAllCpuStatisticsByVdsId() {
    List<CpuStatistics> result =
        vdsCpuStatisticsDao.getAllCpuStatisticsByVdsId(existingVds.getId());

    assertNotNull(result);
    assertEquals(2, result.size());
  }
Exemplo n.º 17
0
 @Override
 public Response add(Host host) {
   validateParameters(host, "name", "address", "rootPassword");
   VdsStatic staticHost = getMapper(Host.class, VdsStatic.class).map(host, null);
   staticHost.setvds_group_id(getClusterId(host));
   AddVdsActionParameters addParams =
       new AddVdsActionParameters(staticHost, host.getRootPassword());
   if (host.isSetOverrideIptables()) {
     addParams.setOverrideFirewall(host.isOverrideIptables());
   }
   if (host.isSetRebootAfterInstallation()) {
     addParams.setRebootAfterInstallation(host.isRebootAfterInstallation());
   }
   return performCreation(
       VdcActionType.AddVds,
       addParams,
       new QueryIdResolver(VdcQueryType.GetVdsByVdsId, GetVdsByVdsIdParameters.class));
 }
  @Override
  protected void executeQueryCommand() {
    VdsStatic host = getDbFacade().getVdsStaticDao().get(getParameters().getId());
    if (host == null) {
      failWith(EngineMessage.ACTION_TYPE_FAILED_HOST_NOT_EXIST);
      return;
    }

    Provider<?> provider = getHostProvider(host);
    if (provider == null) {
      failWith(EngineMessage.NO_FOREMAN_PROVIDER_FOR_HOST);
      return;
    }

    HostProviderProxy proxy = getHostProviderProxy(provider);
    ErrataData errataForHost =
        proxy.getErrataForHost(host.getHostName(), getParameters().getErrataFilter());
    setReturnValue(errataForHost.getErrataCounts());
  }
  @Test
  public void testMassUpdateCpuStatistics() {
    List<CpuStatistics> result =
        vdsCpuStatisticsDao.getAllCpuStatisticsByVdsId(existingVds.getId());
    assertNotNull(result);
    assertEquals(2, result.size());
    assertEquals(20, result.get(0).getCpuUsagePercent());
    assertEquals(20, result.get(1).getCpuUsagePercent());

    result.get(0).setCpuUsagePercent(30);
    result.get(1).setCpuUsagePercent(30);
    vdsCpuStatisticsDao.massUpdateCpuStatistics(result, existingVds.getId());

    result = vdsCpuStatisticsDao.getAllCpuStatisticsByVdsId(existingVds.getId());
    assertNotNull(result);
    assertEquals(2, result.size());
    assertEquals(30, result.get(0).getCpuUsagePercent());
    assertEquals(30, result.get(1).getCpuUsagePercent());
  }
 private Provider<?> getHostProvider(VdsStatic host) {
   return host.getHostProviderId() == null
       ? null
       : getDbFacade().getProviderDao().get(host.getHostProviderId());
 }
 private VdsStatic getVdsStatic() {
   VdsStatic vds = new VdsStatic();
   vds.setClusterId(clusterId);
   vds.setHostName(serverName);
   return vds;
 }
    @Override
    public VdsStatic mapRow(ResultSet rs, int rowNum) throws SQLException {
      VdsStatic entity = new VdsStatic();
      entity.setHostName(rs.getString("host_name"));
      entity.setComment(rs.getString("free_text_comment"));
      entity.setManagementIp(rs.getString("ip"));
      entity.setUniqueID(rs.getString("vds_unique_id"));
      entity.setPort(rs.getInt("port"));
      entity.setProtocol(VdsProtocol.fromValue(rs.getInt("protocol")));
      entity.setVdsGroupId(getGuidDefaultEmpty(rs, "vds_group_id"));
      entity.setId(getGuidDefaultEmpty(rs, "vds_id"));
      entity.setSshPort(rs.getInt("ssh_port"));
      entity.setSshUsername(rs.getString("ssh_username"));
      entity.setVdsGroupId(Guid.createGuidFromStringDefaultEmpty(rs.getString("vds_group_id")));
      entity.setId(Guid.createGuidFromStringDefaultEmpty(rs.getString("vds_id")));
      entity.setVdsName(rs.getString("vds_name"));
      entity.setServerSslEnabled(rs.getBoolean("server_SSL_enabled"));
      entity.setVdsType(VDSType.forValue(rs.getInt("vds_type")));
      entity.setVdsStrength(rs.getInt("vds_strength"));
      entity.setPmType(rs.getString("pm_type"));
      entity.setPmUser(rs.getString("pm_user"));
      entity.setPmPassword(DbFacadeUtils.decryptPassword(rs.getString("pm_password")));
      entity.setPmPort((Integer) rs.getObject("pm_port"));
      entity.setPmOptions(rs.getString("pm_options"));
      entity.setPmEnabled(rs.getBoolean("pm_enabled"));
      entity.setPmProxyPreferences(rs.getString("pm_proxy_preferences"));
      entity.setPmSecondaryIp((rs.getString("pm_secondary_ip")));
      entity.setPmSecondaryType(rs.getString("pm_secondary_type"));
      entity.setPmSecondaryUser(rs.getString("pm_secondary_user"));
      entity.setPmSecondaryPassword(
          DbFacadeUtils.decryptPassword(rs.getString("pm_secondary_password")));
      entity.setPmSecondaryPort((Integer) rs.getObject("pm_secondary_port"));
      entity.setPmSecondaryOptions(rs.getString("pm_secondary_options"));
      entity.setPmSecondaryConcurrent(rs.getBoolean("pm_secondary_concurrent"));
      entity.setPmKdumpDetection(rs.getBoolean("pm_detect_kdump"));
      entity.setOtpValidity(rs.getLong("otp_validity"));
      entity.setSshKeyFingerprint(rs.getString("sshKeyFingerprint"));
      entity.setConsoleAddress(rs.getString("console_address"));
      entity.setDisablePowerManagementPolicy(rs.getBoolean("disable_auto_pm"));

      return entity;
    }
 private MapSqlParameterSource getInsertOrUpdateParams(final VdsStatic vds) {
   return getCustomMapSqlParameterSource()
       .addValue("host_name", vds.getHostName())
       .addValue("free_text_comment", vds.getComment())
       .addValue("ip", vds.getManagementIp())
       .addValue("vds_unique_id", vds.getUniqueID())
       .addValue("port", vds.getPort())
       .addValue("protocol", vds.getProtocol())
       .addValue("vds_group_id", vds.getVdsGroupId())
       .addValue("vds_id", vds.getId())
       .addValue("vds_name", vds.getName())
       .addValue("server_SSL_enabled", vds.isServerSslEnabled())
       .addValue("vds_type", vds.getVdsType())
       .addValue("vds_strength", vds.getVdsStrength())
       .addValue("pm_type", vds.getPmType())
       .addValue("pm_user", vds.getPmUser())
       .addValue("pm_password", DbFacadeUtils.encryptPassword(vds.getPmPassword()))
       .addValue("pm_port", vds.getPmPort())
       .addValue("pm_options", vds.getPmOptions())
       .addValue("pm_enabled", vds.isPmEnabled())
       .addValue("pm_proxy_preferences", vds.getPmProxyPreferences())
       .addValue("pm_secondary_ip", vds.getPmSecondaryIp())
       .addValue("pm_secondary_type", vds.getPmSecondaryType())
       .addValue("pm_secondary_user", vds.getPmSecondaryUser())
       .addValue(
           "pm_secondary_password", DbFacadeUtils.encryptPassword(vds.getPmSecondaryPassword()))
       .addValue("pm_secondary_port", vds.getPmSecondaryPort())
       .addValue("pm_secondary_options", vds.getPmSecondaryOptions())
       .addValue("pm_secondary_concurrent", vds.isPmSecondaryConcurrent())
       .addValue("pm_detect_kdump", vds.isPmKdumpDetection())
       .addValue("otp_validity", vds.getOtpValidity())
       .addValue("vds_spm_priority", vds.getVdsSpmPriority())
       .addValue("console_address", vds.getConsoleAddress())
       .addValue("sshKeyFingerprint", vds.getSshKeyFingerprint())
       .addValue("ssh_port", vds.getSshPort())
       .addValue("ssh_username", vds.getSshUsername())
       .addValue("disable_auto_pm", vds.isDisablePowerManagementPolicy());
 }