@Override public Guid getId() { return vdsStatic.getId(); }
public VdsOperationActionParameters(VdsStatic vdsStaticVal, String passwordVal) { super(vdsStaticVal.getId()); vdsStatic = vdsStaticVal; password = passwordVal; authMethod = AuthenticationMethod.Password; enableSerialConsole = true; affinityLabels = new ArrayList<>(); }
@Override public String toString() { // note that vdsStatic may be null, so the getName with no null protection // is not enough, remove this once vdsStatic can not be null return "Host[" + (vdsStatic == null ? "null" : (vdsStatic.getName() + "," + vdsStatic.getId())) + "]"; }
private Guid getHostId(String host) { try { return Guid.createGuidFromString(host); } catch(IllegalArgumentException exception) { VdsStatic entity = getEntity( VdsStatic.class, QueryType.GetVdsStaticByName, new NameQueryParameters(host), host ); if (entity != null) { return entity.getId(); } return Guid.Empty; } }
private Guid getHostId(String host) { try { return Guid.createGuidFromString(host); } catch (IllegalArgumentException exception) { VdsStatic entity = getEntity( VdsStatic.class, QueryType.GetVdsStaticByName, new NameQueryParameters(host), host ); if (entity != null) { return entity.getId(); } return Guid.Empty; } }
@Test public void testAddHostToLabels() { Label label = createAndSaveLabel("test_label"); Label label2 = createAndSaveLabel("test_label_2"); List<Label> labelsToAssign = Lists.newArrayList(label, label2); List<Guid> guidsForLabelsToAssign = labelsToAssign.stream() .map(Label::getId) .collect(Collectors.toList()); dao.addHostToLabels(host.getId(), guidsForLabelsToAssign); List<Label> assignedLabels = dao.getAllByEntityIds(Lists.newArrayList(host.getId())); assertNotNull(assignedLabels); assertTrue(labelsToAssign.containsAll(assignedLabels) && assignedLabels.containsAll(labelsToAssign)); }
@Test public void testUpdateLabelsForHost() { Label label = createAndSaveLabel("test_label"); dao.addHostToLabels(host.getId(), Lists.newArrayList(label.getId())); Label label2 = createAndSaveLabel("test_label_2"); dao.updateLabelsForHost(host.getId(), Lists.newArrayList(label2.getId())); List<Label> assignedLabels = dao.getAllByEntityIds(Lists.newArrayList(host.getId())); assertNotNull(assignedLabels); assertEquals(Lists.newArrayList(label2), assignedLabels); }
private Guid getHostId(Host host) { // presence of host ID or name already validated return host.isSetId() ? new Guid(host.getId()) : host.isSetName() ? getEntity(VdsStatic.class, QueryType.GetVdsStaticByName, new NameQueryParameters(host.getName()), "Hosts: name=" + host.getName()).getId() : null; } }
@Override public void save(VdsStatic vds) { Guid id = vds.getId(); if (Guid.isNullOrEmpty(id)) { id = Guid.newGuid(); vds.setId(id); } new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("InsertVdsStatic") .execute(getInsertOrUpdateParams(vds)); }
private Guid getHostId(StorageDomain storageDomain) { // presence of host ID or name already validated return storageDomain.getHost().isSetId() ? new Guid(storageDomain.getHost().getId()) : storageDomain.getHost().isSetName() ? getEntity(VdsStatic.class, QueryType.GetVdsStaticByName, new NameQueryParameters(storageDomain.getHost().getName()), "Hosts: name=" + storageDomain.getHost().getName()).getId() : null; }
@Test public void testCreateAndGetLabelWithTwoItems() { VmStatic vm = createAndSaveVm(); Label label = new LabelBuilder() .name("test label") .id(Guid.newGuid()) .entities(host, vm) .build(); dao.save(label); List<Label> read = dao.getAllByEntityIds(Lists.newArrayList(host.getId(), vm.getId())); assertNotNull(read); assertEquals(1, read.size()); }
@Test public void testCreateAndGetWithHost() { Guid guid = Guid.newGuid(); Label label = new LabelBuilder() .name("test label") .id(guid) .entity(host) .build(); dao.save(label); Label read = dao.get(guid); assertNotNull(read); assertEquals(guid, read.getId()); assertEquals(label.getName(), read.getName()); assertNotNull(read.getVms()); assertEquals(0, read.getVms().size()); assertEquals(1, read.getHosts().size()); assertEquals(host.getId(), read.getHosts().iterator().next()); }
@Test public void testCreateAndDeleteById() { Guid guid = Guid.newGuid(); Label label = new LabelBuilder() .name("test label") .id(guid) .host(host.getId()) .build(); dao.save(label); dao.remove(label.getId()); Label read = dao.get(guid); assertNull(read); }
@Test public void testCreateAndGetByReferencedId() { Label label = new LabelBuilder() .name("test label") .id(Guid.newGuid()) .entity(host) .build(); dao.save(label); VmStatic vm = createAndSaveVm(); label = new LabelBuilder() .name("test label 2") .id(Guid.newGuid()) .entity(vm) .build(); dao.save(label); VmStatic vm2 = createAndSaveVm(); label = new LabelBuilder() .name("test label not in result") .id(Guid.newGuid()) .entity(vm2) .build(); dao.save(label); List<Label> read = dao.getAllByEntityIds(Lists.newArrayList(host.getId(), vm.getId(), Guid.newGuid())); assertNotNull(read); assertEquals(2, read.size()); }
@Override protected VDS getInverse(VdsStatic to) { VDS inverse = new VDS(); inverse.setId(to.getId()); inverse.setVdsName(to.getName()); inverse.setHostName(to.getHostName()); inverse.setClusterId(to.getClusterId()); inverse.setPort(to.getPort()); inverse.setSshKeyFingerprint(to.getSshKeyFingerprint()); inverse.setHostProviderId(to.getHostProviderId()); inverse.setSshPort(to.getSshPort()); inverse.setSshUsername(to.getSshUsername()); inverse.setVdsSpmPriority(to.getVdsSpmPriority()); inverse.setConsoleAddress(to.getConsoleAddress()); inverse.setComment(to.getComment()); return inverse; }
private MapSqlParameterSource getInsertOrUpdateParams(final VdsStatic vds) { return getCustomMapSqlParameterSource() .addValue("host_name", vds.getHostName()) .addValue("free_text_comment", vds.getComment()) .addValue("vds_unique_id", vds.getUniqueID()) .addValue("port", vds.getPort()) .addValue("cluster_id", vds.getClusterId()) .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_enabled", vds.isPmEnabled()) .addValue("pm_proxy_preferences", FenceProxySourceTypeHelper.saveAsString(vds.getFenceProxySources())) .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()) .addValue("host_provider_id", vds.getHostProviderId()) .addValue("openstack_network_provider_id", vds.getOpenstackNetworkProviderId()) .addValue("kernel_cmdline", KernelCmdlineColumn.fromVdsStatic(vds).toJson()) .addValue("last_stored_kernel_cmdline", vds.getLastStoredKernelCmdline()) .addValue("reinstall_required", vds.isReinstallRequired()) .addValue("vgpu_placement", vds.getVgpuPlacement()); }