protected Guid lookupClusterId(Host host) { return host.getCluster().isSetId() ? asGuid(host.getCluster().getId()) : lookupClusterByName(host.getCluster().getName()).getId(); }
public static Method getAddSignature(Host host) throws NoSuchMethodException, SecurityException { if (host == null) { throw new ValidationException("Parameter 'host' is mandatory but was not provided."); } if (host.getAddress()==null) { throw new ValidationException("Parameter 'host.address' is mandatory but was not provided."); } if (host.getName()==null) { throw new ValidationException("Parameter 'host.name' is mandatory but was not provided."); } if ( (host.getCluster()==null || host.getCluster().getId()==null) && (host.getCluster()==null || host.getCluster().getName()==null) ) { throw new ValidationException("Parameters 'host.cluster.id' or 'host.cluster.name' are mandatory but both were not provided."); } /** * using_root_password */ if (host!=null && host.getRootPassword()!=null ) { return HostsResource.class.getMethod("addUsingRootPassword", Host.class); } throw new ValidationException("No matching signature found, make sure that mandatory attributes are provided."); }
private Guid getClusterId(Host host) { if (host.isSetCluster()) { org.ovirt.engine.api.model.Cluster cluster = host.getCluster(); if (cluster.isSetId()) { return asGuid(cluster.getId()); } if (cluster.isSetName()) { return getClusterIdByName(cluster.getName()); } } return getClusterIdByName(DEFAULT_NAME); }
private Host setCluster(Host host, org.ovirt.engine.api.model.Cluster cluster) { if (cluster.isSetId()) { host.setCluster(cluster); } else { host.setCluster(new org.ovirt.engine.api.model.Cluster()); host.getCluster().setId(lookupClusterByName(cluster.getName()).getId().toString()); } return host; }
@Override public Host update(Host incoming) { QueryIdResolver<Guid> hostResolver = new QueryIdResolver<>(QueryType.GetVdsByVdsId, IdQueryParameters.class); VDS entity = getEntity(hostResolver, true); BackendExternalProviderHelper.completeExternalNetworkProviderConfigurations(this, incoming.getExternalNetworkProviderConfigurations()); // if fence agents list is null set it to null in entity if(incoming.getAgents() == null) { entity.setFenceAgents(null); } if (incoming.isSetCluster() && (incoming.getCluster().isSetId() || incoming.getCluster().isSetName())) { Guid clusterId = lookupClusterId(incoming); if (!clusterId.equals(entity.getClusterId())) { performAction(ActionType.ChangeVDSCluster, new ChangeVDSClusterParameters(clusterId, guid)); // After changing the cluster with the specialized command we need to reload the entity, so that it // contains the new cluster id. If we don't do this the next command will think that we are trying // to change the cluster, and it will explicitly refuse to perform the update. entity = getEntity(hostResolver, true); } } Host host = performUpdate(incoming, entity, map(entity), hostResolver, ActionType.UpdateVds, new UpdateParametersProvider()); return host; }
@Test public void testBadGuidValidation() { setUpGetEntityExpectations(false); Host host = new Host(); host.setCluster(new Cluster()); host.getCluster().setId("!!!"); assertThrows(MalformedIdException.class, () -> resource.update(host)); }
@Test public void testAddHostClusterById() { setUriInfo(setUpBasicUriExpectations()); setUpCreationExpectations(ActionType.AddVds, AddVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true, GUIDS[0], QueryType.GetVdsByVdsId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0)); Host model = getModel(0); model.setCluster(new Cluster()); model.getCluster().setId(GUIDS[1].toString()); Response response = collection.add(model); assertEquals(201, response.getStatus()); assertTrue(response.getEntity() instanceof Host); verifyModel((Host) response.getEntity(), 0); }
@Test public void testAddHostClusterByName() { setUriInfo(setUpBasicUriExpectations()); setUpEntityQueryExpectations(QueryType.GetClusterByName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[1] }, setUpCluster(GUIDS[1])); setUpCreationExpectations(ActionType.AddVds, AddVdsActionParameters.class, new String[] { "RootPassword" }, new Object[] { ROOT_PASSWORD }, true, true, GUIDS[0], QueryType.GetVdsByVdsId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0)); Host model = getModel(0); model.setCluster(new Cluster()); model.getCluster().setName(NAMES[1]); Response response = collection.add(model); assertEquals(201, response.getStatus()); assertTrue(response.getEntity() instanceof Host); verifyModel((Host) response.getEntity(), 0); }
@Override protected void verify(Host model, Host transform) { assertNotNull(transform); assertEquals(model.getName(), transform.getName()); assertEquals(model.getComment(), transform.getComment()); assertEquals(model.getId(), transform.getId()); assertNotNull(transform.getCluster()); assertEquals(model.getCluster().getId(), transform.getCluster().getId()); assertEquals(model.getAddress(), transform.getAddress()); assertEquals(model.getPort(), transform.getPort()); assertEquals(model.getSpm().getPriority(), transform.getSpm().getPriority()); assertEquals(model.getDisplay().getAddress(), transform.getDisplay().getAddress()); }
entity.setName(model.getName()); if (model.isSetCluster() && model.getCluster().isSetId()) { entity.setClusterId(GuidUtils.asGuid(model.getCluster().getId()));
to.setCluster(adaptOut(from.getCluster()));