Juan Hernandez has uploaded a new change for review. Change subject: restapi: Foreman host provider ......................................................................
restapi: Foreman host provider This patch adds the resources for the Foreman host providers. The representation of the resource will look like this: GET /foremanhostproviders <foreman_host_providers> <foreman_host_provider id="{provider:id}">...</foreman_host_provider> ... </foreman_host_providers> GET /foremanhostproviders/{provider:id} <foreman_host_provider id="{provider:id}"> <name>myprovider</name> <description>My provider</description> <url>http://foreman.example.com</url> <requires_authentication>true</requires_authentication> <username>myuser</username> <password>mypass</password> <properties> <property> <name>prop1</name> <value>value1</myvalue> </property> <property> <name>prop2</name> <value>value2</myvalue> </property> </properties> </foreman_host_provider> The providers collection will support listing, getting, adding, and removing providers, with the usual methods. The provider resource will support the getting, deleting and updating the provider, with the usual methods. In addition it will support the "testconnectivity" and "importcertificates" operation. The first is used to check the connectivity with the external provider: POST /foremanhostproviders/{provider:id}/testconnectivity <action/> The second is used to import the chain of certificates of the external provider: POST /foremanhostproviders/{provider:id}/importcertificates <action/> The provider resource includes subcollections for certificates, hosts, host groups and compute resources, all of them read only. For certificates it will look like this: GET /foremanhostproviders/{provider:id}/certificates <certificates> <certificate id="{host:id}">...</certificate> ... </fcertificates> GET /foremanhostproviders/{provider:id}/certificates/{certificate:id} <certificate id="{certificate:id}"> <subject>CN=foreman.example.com</subject> <content>...</content> </certificate> For hosts: GET /foremanhostproviders/{provider:id}/hosts <foreman_hosts> <foreman_host id="{host:id}">...</foreman_host> ... </foreman_hosts> GET /foremanhostproviders/{provider:id}/hosts/{host:id} <foreman_host id="{host:id}"> <name>myhost</name> <address>mhost.example.com</address> </foreman_host> For host groups: GET /foremanhostproviders/{provider:id}/hostgroups <foreman_host_groups> <foreman_host_group id="{group:id}">...</foreman_host_group> ... </foreman_host_groups> GET /foremanhostproviders/{provider:id}/hostgroups/{group:id} <foreman_host_group id="{group:id}"> <name>mygroup</name> </foreman_host_group> For compute resources: GET /foremanhostproviders/{provider:id}/computeresources <foreman_compute_resources> <foreman_compute_resource id="{resource:id}">...</foreman_compute_resource> ... </foreman_compute_resources> GET /foremanhostproviders/{provider:id}/computeresources/{resource:id} <foreman_compute_resource id="{resource:id}"> <name>myresource</name> </foreman_compute_resource> Change-Id: I2144125f00822263dc68da881eb3180c4cd6b237 Related-To: https://bugzilla.redhat.com/1132259 Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com> --- A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourceResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourcesResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupsResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProviderResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProvidersResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostResource.java A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostsResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResourceTest.java A backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapper.java A backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapper.java A backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapper.java A backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapper.java A backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapperTest.java A backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapperTest.java A backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapperTest.java A backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapperTest.java 38 files changed, 2,637 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/69/33969/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourceResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourceResource.java new file mode 100644 index 0000000..1380ddb --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourceResource.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.GET; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.resource.ApiMediaType; + +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanComputeResourceResource { + @GET + public ForemanComputeResource get(); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourcesResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourcesResource.java new file mode 100644 index 0000000..7539658 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanComputeResourcesResource.java @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.ForemanComputeResources; +import org.ovirt.engine.api.resource.ApiMediaType; + +@Path("computeresources") +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanComputeResourcesResource { + @GET + public ForemanComputeResources list(); + + @Path("{id}") + ForemanComputeResourceResource getForemanComputeResource(@PathParam("id") String id); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupResource.java new file mode 100644 index 0000000..a891231 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupResource.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.GET; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.resource.ApiMediaType; + +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanHostGroupResource { + @GET + public ForemanHostGroup get(); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupsResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupsResource.java new file mode 100644 index 0000000..1d89af6 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostGroupsResource.java @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.ForemanHostGroups; +import org.ovirt.engine.api.resource.ApiMediaType; + +@Path("hostgroups") +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanHostGroupsResource { + @GET + public ForemanHostGroups list(); + + @Path("{id}") + ForemanHostGroupResource getForemanHostGroup(@PathParam("id") String id); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProviderResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProviderResource.java new file mode 100644 index 0000000..dada557 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProviderResource.java @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.resource.ApiMediaType; +import org.ovirt.engine.api.resource.ExternalProviderResource; + +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanHostProviderResource extends ExternalProviderResource<ForemanHostProvider> { + @Path("hosts") + public ForemanHostsResource getForemanHosts(); + + @Path("hostgroups") + public ForemanHostGroupsResource getForemanHostGroups(); + + @Path("computeresources") + public ForemanComputeResourcesResource getForemanComputeResources(); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProvidersResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProvidersResource.java new file mode 100644 index 0000000..967336a --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostProvidersResource.java @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.model.ForemanHostProviders; +import org.ovirt.engine.api.resource.ApiMediaType; + +@Path("/foremanhostproviders") +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanHostProvidersResource { + @GET + public ForemanHostProviders list(); + + @POST + @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) + public Response add(ForemanHostProvider provider); + + @DELETE + @Path("{id}") + public Response remove(@PathParam("id") String id); + + @Path("{id}") + public ForemanHostProviderResource getForemanHostProvider(@PathParam("id") String id); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostResource.java new file mode 100644 index 0000000..65852e6 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostResource.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.GET; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.resource.ApiMediaType; + +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanHostResource { + @GET + public ForemanHost get(); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostsResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostsResource.java new file mode 100644 index 0000000..87a580e --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/foreman/ForemanHostsResource.java @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.foreman; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.model.ForemanHosts; +import org.ovirt.engine.api.resource.ApiMediaType; + +@Path("images") +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface ForemanHostsResource { + @GET + public ForemanHosts list(); + + @Path("{id}") + ForemanHostResource getForemanHost(@PathParam("id") String id); +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java index 0f4fb66..7561ff7 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java @@ -58,6 +58,7 @@ links.add(createLink("schedulingpolicies", baseUri)); links.add(createLink("permissions", baseUri)); links.add(createLink("macpools", baseUri)); + links.add(createLink("foremanhostproviders", baseUri)); return links; } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java index 2c8b925..9dc50b0 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java @@ -47,6 +47,10 @@ import org.ovirt.engine.api.model.Event; import org.ovirt.engine.api.model.File; import org.ovirt.engine.api.model.Filter; +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.model.ForemanHostProvider; import org.ovirt.engine.api.model.GlusterBrick; import org.ovirt.engine.api.model.GlusterHook; import org.ovirt.engine.api.model.GlusterVolume; @@ -220,6 +224,14 @@ import org.ovirt.engine.api.resource.aaa.GroupsResource; import org.ovirt.engine.api.resource.aaa.UserResource; import org.ovirt.engine.api.resource.aaa.UsersResource; +import org.ovirt.engine.api.resource.foreman.ForemanComputeResourceResource; +import org.ovirt.engine.api.resource.foreman.ForemanComputeResourcesResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostGroupResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostGroupsResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostProviderResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostProvidersResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostsResource; import org.ovirt.engine.api.resource.gluster.GlusterBrickResource; import org.ovirt.engine.api.resource.gluster.GlusterBricksResource; import org.ovirt.engine.api.resource.gluster.GlusterHookResource; @@ -479,6 +491,21 @@ map = new ParentToCollectionMap(CpuProfileResource.class, CpuProfilesResource.class); TYPES.put(CpuProfile.class, map); + // Foreman host providers: + map = new ParentToCollectionMap(ForemanHostProviderResource.class, ForemanHostProvidersResource.class); + TYPES.put(ForemanHostProvider.class, map); + + map = new ParentToCollectionMap(ForemanHostResource.class, ForemanHostsResource.class); + map.add(ForemanHostResource.class, ForemanHostsResource.class, ForemanHostProvider.class); + TYPES.put(ForemanHost.class, map); + + map = new ParentToCollectionMap(ForemanHostGroupResource.class, ForemanHostGroupsResource.class); + map.add(ForemanHostGroupResource.class, ForemanHostGroupsResource.class, ForemanHostProvider.class); + TYPES.put(ForemanHostGroup.class, map); + + map = new ParentToCollectionMap(ForemanComputeResourceResource.class, ForemanComputeResourcesResource.class); + map.add(ForemanComputeResourceResource.class, ForemanComputeResourcesResource.class, ForemanHostProvider.class); + TYPES.put(ForemanComputeResource.class, map); } /** diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 711f2a0..a81b01c 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -4943,4 +4943,122 @@ </xs:complexContent> </xs:complexType> + <!-- Foreman host providers: --> + <xs:element name="foreman_host_provider" type="ForemanHostProvider"/> + + <xs:complexType name="ForemanHostProvider"> + <xs:complexContent> + <xs:extension base="ExternalProvider"/> + </xs:complexContent> + </xs:complexType> + + <xs:element name="foreman_host_providers" type="ForemanHostProviders"/> + + <xs:complexType name="ForemanHostProviders"> + <xs:complexContent> + <xs:extension base="BaseResources"> + <xs:sequence> + <xs:element ref="foreman_host_provider" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:appinfo> + <jaxb:property name="ForemanHostProviders"/> + </xs:appinfo> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:element name="foreman_host" type="ForemanHost"/> + + <xs:element name="foreman_hosts" type="ForemanHosts"/> + + <xs:complexType name="ForemanHost"> + <xs:complexContent> + <xs:extension base="BaseResource"> + <xs:sequence> + <xs:element ref="foreman_host_provider" minOccurs="0" maxOccurs="1"/> + <xs:element name="address" type="xs:string" minOccurs="0" maxOccurs="1"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="ForemanHosts"> + <xs:complexContent> + <xs:extension base="BaseResources"> + <xs:sequence> + <xs:element ref="foreman_host" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:appinfo> + <jaxb:property name="ForemanHosts"/> + </xs:appinfo> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:element name="foreman_host_group" type="ForemanHostGroup"/> + + <xs:element name="foreman_hosts_group" type="ForemanHostGroups"/> + + <xs:complexType name="ForemanHostGroup"> + <xs:complexContent> + <xs:extension base="BaseResource"> + <xs:sequence> + <xs:element ref="foreman_host_provider" minOccurs="0" maxOccurs="1"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="ForemanHostGroups"> + <xs:complexContent> + <xs:extension base="BaseResources"> + <xs:sequence> + <xs:element ref="foreman_host_group" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:appinfo> + <jaxb:property name="ForemanHostGroups"/> + </xs:appinfo> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:element name="foreman_compute_resource" type="ForemanComputeResource"/> + + <xs:element name="foreman_compute_resources" type="ForemanComputeResources"/> + + <xs:complexType name="ForemanComputeResource"> + <xs:complexContent> + <xs:extension base="BaseResource"> + <xs:sequence> + <xs:element ref="foreman_host_provider" minOccurs="0" maxOccurs="1"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + + <xs:complexType name="ForemanComputeResources"> + <xs:complexContent> + <xs:extension base="BaseResources"> + <xs:sequence> + <xs:element ref="foreman_compute_resource" minOccurs="0" maxOccurs="unbounded"> + <xs:annotation> + <xs:appinfo> + <jaxb:property name="ForemanComputeResources"/> + </xs:appinfo> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + </xs:schema> diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml index ae43b7b..6fe4829 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml @@ -6132,3 +6132,168 @@ Content-Type: {value: application/xml|json, required: true} Expect: {value: 201-created, required: false} Correlation-Id: {value: 'any string', required: false} + +- name: /foremanhostproviders|rel=get + description: get the list of all Foreman host providers in the system + request: + body: + parameterType: null + signatures: [] + urlparams: + max: {context: matrix, type: 'xs:int', value: 'max results', required: false} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}|rel=get + description: get the details of the specified Foreman host provider in the system + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}|rel=delete + description: delete the specified Foreman host provider in the system + request: + body: + parameterType: null + signatures: [] + urlparams: + async: {context: matrix, type: 'xs:boolean', value: true|false, required: false} + headers: + Correlation-Id: {value: 'any string', required: false} +- name: /foremanhostproviders/{foremanhostprovider:id}|rel=update + description: update the specified Foreman host provider in the system + request: + body: + parameterType: ForemanHostProvider + signatures: + - mandatoryArguments: {} + optionalArguments: + foreman_host_provider.name: xs:string + foreman_host_provider.description: xs:string + foreman_host_provider.requires_authentication: xs:boolean + foreman_host_provider.username: xs:string + foreman_host_provider.password: xs:string + foreman_host_provider.properties.property--COLLECTION: + property.name: xs:string + property.value: xs:string + description: update the specified Foreman host provider in the system + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Correlation-Id: {value: 'any string', required: false} +- name: /foremanhostproviders|rel=add + description: add a new Foreman host provider to the system + request: + body: + parameterType: ForemanHostProvider + signatures: + - mandatoryArguments: + foreman_host_provider.name: xs:string + optionalArguments: + foreman_host_provider.description: xs:string + foreman_host_provider.url: xs:string + foreman_host_provider.requires_authentication: xs:boolean + foreman_host_provider.username: xs:string + foreman_host_provider.password: xs:string + foreman_host_provider.properties.property--COLLECTION: + property.name: xs:string + property.value: xs:string + description: add a new Foreman host provider to the system + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Expect: {value: 201-created, required: false} + Correlation-Id: {value: 'any string', required: false} +- name: /foremanhostproviders/{foremanhostprovider:id}/testconnectivity|rel=testconnectivity + description: test the connectivity to the external Foreman host provider + request: + body: + parameterType: Action + signatures: + - mandatoryArguments: {} + optionalArguments: {} + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Correlation-Id: {value: 'any string', required: false} +- name: /foremanhostproviders/{foremanhostprovider:id}/importcertificates|rel=importcertificates + description: import the SSL certificates of the Foreman host provider + request: + body: + parameterType: Action + signatures: + - mandatoryArguments: {} + optionalArguments: {} + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Correlation-Id: {value: 'any string', required: false} +- name: /foremanhostproviders/{foremanhostprovider:id}/certificates|rel=get + description: get the list of certificates of the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: + max: {context: matrix, type: 'xs:int', value: 'max results', required: false} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}/certificates/{certificate:id}|rel=get + description: get the details of the specified certificate of the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}/hosts|rel=get + description: get the list of hosts from the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: + max: {context: matrix, type: 'xs:int', value: 'max results', required: false} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}/hosts/{host:id}|rel=get + description: get the details of the specified host from the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}/hostgroups|rel=get + description: get the list of host groups from the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: + max: {context: matrix, type: 'xs:int', value: 'max results', required: false} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}/hostgroups/{hostgroup:id}|rel=get + description: get the details of the specified host group from the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}/computeresources|rel=get + description: get the list of compute resources from the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: + max: {context: matrix, type: 'xs:int', value: 'max results', required: false} + headers: {} +- name: /foremanhostproviders/{foremanhostprovider:id}/computeresources/{computeresource:id}|rel=get + description: get the details of the specified compute resource from the Foreman host provider + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} + diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java index 9ec8c77..905a2d1 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java @@ -57,6 +57,7 @@ import org.ovirt.engine.api.restapi.resource.aaa.BackendDomainsResource; import org.ovirt.engine.api.restapi.resource.aaa.BackendGroupsResource; import org.ovirt.engine.api.restapi.resource.aaa.BackendUsersResource; +import org.ovirt.engine.api.restapi.resource.foreman.BackendForemanHostProvidersResource; import org.ovirt.engine.api.restapi.resource.validation.IOExceptionMapper; import org.ovirt.engine.api.restapi.resource.validation.JsonExceptionMapper; import org.ovirt.engine.api.restapi.resource.validation.MalformedIdExceptionMapper; @@ -145,6 +146,7 @@ addResource(new BackendSystemPermissionsResource()); addResource(new BackendDiskProfilesResource()); addResource(new BackendCpuProfilesResource()); + addResource(new BackendForemanHostProvidersResource()); final SessionProcessor processor = new SessionProcessor(); processor.setBackend(backend); diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResource.java new file mode 100644 index 0000000..d0f4f6c --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResource.java @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; + +import java.util.List; + +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.resource.foreman.ForemanComputeResourceResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource; +import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper; +import org.ovirt.engine.core.common.businessentities.ExternalComputeResource; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendForemanComputeResourceResource + extends AbstractBackendActionableResource<ForemanComputeResource, ExternalComputeResource> + implements ForemanComputeResourceResource { + + private String providerId; + + protected BackendForemanComputeResourceResource(String id, String providerId) { + super(id, ForemanComputeResource.class, ExternalComputeResource.class); + this.providerId = providerId; + } + + @Override + public ForemanComputeResource get() { + // Convert the resource identifier to the host group name: + String computeResourceName = hex2string(id); + + // The backend query that retrieves the list of hosts groups needs a complete provider instance, the id isn't + // enough: + Provider provider = BackendExternalProviderHelper.getProvider(this, providerId); + + // The backend doesn't have a way to retrieve a host by ide, so we have to iterate them: + ProviderQueryParameters parameters = new ProviderQueryParameters(); + parameters.setProvider(provider); + VdcQueryReturnValue result = runQuery(VdcQueryType.GetComputeResourceFromExternalProvider, parameters); + List<ExternalComputeResource> computeResources = (List<ExternalComputeResource>) result.getReturnValue(); + if (computeResources != null) { + for (ExternalComputeResource computeResource : computeResources) { + if (computeResourceName.equals(computeResource.getName())) { + return addLinks(populate(map(computeResource), computeResource)); + } + } + } + + // No luck: + return notFound(); + } + + @Override + protected ForemanComputeResource doPopulate(ForemanComputeResource model, ExternalComputeResource entity) { + return model; + } + + @Override + protected ForemanComputeResource addParents(ForemanComputeResource model) { + ForemanHostProvider provider = new ForemanHostProvider(); + provider.setId(providerId); + model.setForemanHostProvider(provider); + return super.addParents(model); + } + + /** + * The identifier of a Foreman host isn't a UUID. + */ + @Override + protected Guid asGuidOr404(String id) { + return null; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResource.java new file mode 100644 index 0000000..6478a3c --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResource.java @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import javax.ws.rs.core.Response; +import java.util.List; + +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.model.ForemanComputeResources; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.resource.foreman.ForemanComputeResourceResource; +import org.ovirt.engine.api.resource.foreman.ForemanComputeResourcesResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource; +import org.ovirt.engine.api.restapi.resource.SingleEntityResource; +import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper; +import org.ovirt.engine.core.common.businessentities.ExternalComputeResource; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanComputeResourcesResource + extends AbstractBackendCollectionResource<ForemanComputeResource, ExternalComputeResource> + implements ForemanComputeResourcesResource { + /** + * The identifier of the provider. + */ + private String providerId; + + public BackendForemanComputeResourcesResource(String providerId) { + super(ForemanComputeResource.class, ExternalComputeResource.class); + this.providerId = providerId; + } + + @Override + public ForemanComputeResources list() { + Provider provider = BackendExternalProviderHelper.getProvider(this, providerId); + ProviderQueryParameters parameters = new ProviderQueryParameters(); + parameters.setProvider(provider); + return mapCollection(getBackendCollection(VdcQueryType.GetComputeResourceFromExternalProvider, parameters)); + } + + @Override + protected ForemanComputeResource doPopulate(ForemanComputeResource model, ExternalComputeResource entity) { + return model; + } + + protected ForemanComputeResources mapCollection(List<ExternalComputeResource> entities) { + ForemanComputeResources collection = new ForemanComputeResources(); + for (ExternalComputeResource entity : entities) { + collection.getForemanComputeResources().add(addLinks(populate(map(entity), entity))); + } + return collection; + } + + @Override + protected ForemanComputeResource addParents(ForemanComputeResource model) { + ForemanHostProvider provider = new ForemanHostProvider(); + provider.setId(providerId); + model.setForemanHostProvider(provider); + return super.addParents(model); + } + + @Override + protected Response performRemove(String id) { + throw new UnsupportedOperationException(); + } + + @Override + @SingleEntityResource + public ForemanComputeResourceResource getForemanComputeResource(String id) { + return inject(new BackendForemanComputeResourceResource(id, providerId)); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResource.java new file mode 100644 index 0000000..1b4ffd7 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResource.java @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; + +import java.util.List; + +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.resource.foreman.ForemanHostGroupResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource; +import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper; +import org.ovirt.engine.core.common.businessentities.ExternalHostGroup; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendForemanHostGroupResource + extends AbstractBackendActionableResource<ForemanHostGroup, ExternalHostGroup> + implements ForemanHostGroupResource { + + private String providerId; + + protected BackendForemanHostGroupResource(String id, String providerId) { + super(id, ForemanHostGroup.class, ExternalHostGroup.class); + this.providerId = providerId; + } + + @Override + public ForemanHostGroup get() { + // Convert the resource identifier to the host group name: + String hostGroupName = hex2string(id); + + // The backend query that retrieves the list of hosts groups needs a complete provider instance, the id isn't + // enough: + Provider provider = BackendExternalProviderHelper.getProvider(this, providerId); + + // The backend doesn't have a way to retrieve a host by ide, so we have to iterate them: + ProviderQueryParameters parameters = new ProviderQueryParameters(); + parameters.setProvider(provider); + VdcQueryReturnValue result = runQuery(VdcQueryType.GetHostGroupsFromExternalProvider, parameters); + List<ExternalHostGroup> hostGroups = (List<ExternalHostGroup>) result.getReturnValue(); + if (hostGroups != null) { + for (ExternalHostGroup hostGroup : hostGroups) { + if (hostGroupName.equals(hostGroup.getName())) { + return addLinks(populate(map(hostGroup), hostGroup)); + } + } + } + + // No luck: + return notFound(); + } + + @Override + protected ForemanHostGroup doPopulate(ForemanHostGroup model, ExternalHostGroup entity) { + return model; + } + + @Override + protected ForemanHostGroup addParents(ForemanHostGroup image) { + ForemanHostProvider provider = new ForemanHostProvider(); + provider.setId(providerId); + image.setForemanHostProvider(provider); + return super.addParents(image); + } + + /** + * The identifier of a Foreman host isn't a UUID. + */ + @Override + protected Guid asGuidOr404(String id) { + return null; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResource.java new file mode 100644 index 0000000..ed5633e --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResource.java @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import javax.ws.rs.core.Response; +import java.util.List; + +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.model.ForemanHostGroups; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.resource.foreman.ForemanHostGroupResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostGroupsResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource; +import org.ovirt.engine.api.restapi.resource.SingleEntityResource; +import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper; +import org.ovirt.engine.core.common.businessentities.ExternalHostGroup; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanHostGroupsResource + extends AbstractBackendCollectionResource<ForemanHostGroup, ExternalHostGroup> + implements ForemanHostGroupsResource { + /** + * The identifier of the provider. + */ + private String providerId; + + public BackendForemanHostGroupsResource(String providerId) { + super(ForemanHostGroup.class, ExternalHostGroup.class); + this.providerId = providerId; + } + + @Override + public ForemanHostGroups list() { + Provider provider = BackendExternalProviderHelper.getProvider(this, providerId); + ProviderQueryParameters parameters = new ProviderQueryParameters(); + parameters.setProvider(provider); + return mapCollection(getBackendCollection(VdcQueryType.GetHostGroupsFromExternalProvider, parameters)); + } + + @Override + protected ForemanHostGroup doPopulate(ForemanHostGroup model, ExternalHostGroup entity) { + return model; + } + + protected ForemanHostGroups mapCollection(List<ExternalHostGroup> entities) { + ForemanHostGroups collection = new ForemanHostGroups(); + for (ExternalHostGroup entity : entities) { + collection.getForemanHostGroups().add(addLinks(populate(map(entity), entity))); + } + return collection; + } + + @Override + protected ForemanHostGroup addParents(ForemanHostGroup model) { + ForemanHostProvider provider = new ForemanHostProvider(); + provider.setId(providerId); + model.setForemanHostProvider(provider); + return super.addParents(model); + } + + @Override + protected Response performRemove(String id) { + throw new UnsupportedOperationException(); + } + + @Override + @SingleEntityResource + public ForemanHostGroupResource getForemanHostGroup(String id) { + return inject(new BackendForemanHostGroupResource(id, providerId)); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResource.java new file mode 100644 index 0000000..9559b0df --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResource.java @@ -0,0 +1,109 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.ovirt.engine.api.restapi.resource.foreman.BackendForemanHostProvidersResource.SUB_COLLECTIONS; + +import javax.ws.rs.core.Response; + +import org.ovirt.engine.api.model.Action; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.resource.ExternalProviderCertificatesResource; +import org.ovirt.engine.api.resource.foreman.ForemanComputeResourcesResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostGroupsResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostProviderResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostsResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource; +import org.ovirt.engine.api.restapi.resource.BackendExternalProviderCertificatesResource; +import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper; +import org.ovirt.engine.core.common.action.ProviderParameters; +import org.ovirt.engine.core.common.action.VdcActionParametersBase; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendForemanHostProviderResource extends + AbstractBackendActionableResource<ForemanHostProvider, Provider> implements + ForemanHostProviderResource { + + public BackendForemanHostProviderResource(String id) { + super(id, ForemanHostProvider.class, Provider.class, SUB_COLLECTIONS); + } + + @Override + public ForemanHostProvider get() { + return performGet(VdcQueryType.GetProviderById, new IdQueryParameters(guid)); + } + + @Override + public ForemanHostProvider update(ForemanHostProvider incoming) { + return performUpdate( + incoming, + new QueryIdResolver<Guid>(VdcQueryType.GetProviderById, IdQueryParameters.class), + VdcActionType.UpdateProvider, + new UpdateParametersProvider() + ); + } + + protected class UpdateParametersProvider implements ParametersProvider<ForemanHostProvider, Provider> { + @Override + public VdcActionParametersBase getParameters(ForemanHostProvider incoming, Provider entity) { + return new ProviderParameters(map(incoming, entity)); + } + } + + @Override + protected ForemanHostProvider doPopulate(ForemanHostProvider model, Provider entity) { + return model; + } + + @Override + public Response testConnectivity(Action action) { + Provider provider = BackendExternalProviderHelper.getProvider(this, id); + ProviderParameters parameters = new ProviderParameters(provider); + return performAction(VdcActionType.TestProviderConnectivity, parameters); + } + + @Override + public Response importCertificates(Action action) { + Provider provider = BackendExternalProviderHelper.getProvider(this, id); + ProviderParameters parameters = new ProviderParameters(provider); + return performAction(VdcActionType.ImportProviderCertificateChain, parameters); + } + + @Override + public ForemanHostsResource getForemanHosts() { + return inject(new BackendForemanHostsResource(id)); + } + + @Override + public ForemanHostGroupsResource getForemanHostGroups() { + return inject(new BackendForemanHostGroupsResource(id)); + } + + @Override + public ForemanComputeResourcesResource getForemanComputeResources() { + return inject(new BackendForemanComputeResourcesResource(id)); + } + + @Override + public ExternalProviderCertificatesResource getCertificates() { + return inject(new BackendExternalProviderCertificatesResource(id)); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResource.java new file mode 100644 index 0000000..be78145 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResource.java @@ -0,0 +1,125 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.api.common.util.QueryHelper; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.model.ForemanHostProviders; +import org.ovirt.engine.api.resource.foreman.ForemanHostProviderResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostProvidersResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource; +import org.ovirt.engine.api.restapi.resource.SingleEntityResource; +import org.ovirt.engine.api.restapi.resource.BackendExternalProviderHelper; +import org.ovirt.engine.core.common.action.ProviderParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.businessentities.ProviderType; +import org.ovirt.engine.core.common.interfaces.SearchType; +import org.ovirt.engine.core.common.queries.GetAllProvidersParameters; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendForemanHostProvidersResource + extends AbstractBackendCollectionResource<ForemanHostProvider, Provider> + implements ForemanHostProvidersResource { + /** + * The names of the sub-collections supported by this resource. + */ + public static String[] SUB_COLLECTIONS = { + "hosts", + "hostgroups", + "computeresources", + "certificates" + }; + + public BackendForemanHostProvidersResource() { + super(ForemanHostProvider.class, Provider.class, SUB_COLLECTIONS); + } + + @Override + public ForemanHostProviders list() { + return mapCollection(getBackendCollection()); + } + + private ForemanHostProviders mapCollection(List<Provider> entities) { + ForemanHostProviders collection = new ForemanHostProviders(); + for (Provider entity : entities) { + collection.getForemanHostProviders().add(addLinks(map(entity))); + } + return collection; + } + + private List<Provider> getBackendCollection() { + if (isFiltered()) { + return getBackendCollection( + VdcQueryType.GetAllProviders, + new GetAllProvidersParameters(ProviderType.FOREMAN) + ); + } + else { + return getBackendCollection(SearchType.Provider, getConstraint()); + } + } + + private String getConstraint() { + StringBuilder buffer = new StringBuilder(); + buffer.append("Providers: type="); + buffer.append(ProviderType.FOREMAN.name()); + String query = QueryHelper.getConstraint(getUriInfo(), null, modelType, false); + if (StringUtils.isNotBlank(query)) { + buffer.append(" AND ("); + buffer.append(query); + buffer.append(")"); + } + return buffer.toString(); + } + + @Override + public Response add(ForemanHostProvider provider) { + validateParameters(provider, "name"); + return performCreate( + VdcActionType.AddProvider, + new ProviderParameters(map(provider)), + new QueryIdResolver<Guid>(VdcQueryType.GetProviderById, IdQueryParameters.class) + ); + } + + @Override + protected Response performRemove(String id) { + Provider provider = BackendExternalProviderHelper.getProvider(this, id); + ProviderParameters parameters = new ProviderParameters(provider); + return performAction(VdcActionType.RemoveProvider, parameters); + } + + @Override + protected ForemanHostProvider doPopulate(ForemanHostProvider model, Provider entity) { + return model; + } + + @Override + @SingleEntityResource + public ForemanHostProviderResource getForemanHostProvider(@PathParam("id") String id) { + return inject(new BackendForemanHostProviderResource(id)); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResource.java new file mode 100644 index 0000000..c2cf0b7 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResource.java @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; + +import java.util.List; + +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.resource.foreman.ForemanHostResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.queries.GetHostListFromExternalProviderParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendForemanHostResource + extends AbstractBackendActionableResource<ForemanHost, VDS> + implements ForemanHostResource { + + private String providerId; + + protected BackendForemanHostResource(String id, String providerId) { + super(id, ForemanHost.class, VDS.class); + this.providerId = providerId; + } + + @Override + public ForemanHost get() { + // Convert the resource identifier to the host group name: + String hostName = hex2string(id); + + // The backend doesn't have a way to retrieve a host by ide, so we have to iterate them: + GetHostListFromExternalProviderParameters parameters = new GetHostListFromExternalProviderParameters(); + parameters.setFilterOutExistingHosts(true); + parameters.setProviderId(asGuid(providerId)); + VdcQueryReturnValue result = runQuery(VdcQueryType.GetHostListFromExternalProvider, parameters); + List<VDS> hosts = (List<VDS>) result.getReturnValue(); + if (hosts != null) { + for (VDS host : hosts) { + if (hostName.equals(host.getName())) { + return addLinks(populate(map(host), host)); + } + } + } + + // No luck: + return notFound(); + } + + @Override + protected ForemanHost doPopulate(ForemanHost model, VDS entity) { + return model; + } + + @Override + protected ForemanHost addParents(ForemanHost image) { + ForemanHostProvider provider = new ForemanHostProvider(); + provider.setId(providerId); + image.setForemanHostProvider(provider); + return super.addParents(image); + } + + /** + * The identifier of a Foreman host isn't a UUID. + */ + @Override + protected Guid asGuidOr404(String id) { + return null; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResource.java new file mode 100644 index 0000000..07f332c --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResource.java @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import javax.ws.rs.core.Response; +import java.util.List; + +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.model.ForemanHosts; +import org.ovirt.engine.api.resource.foreman.ForemanHostResource; +import org.ovirt.engine.api.resource.foreman.ForemanHostsResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource; +import org.ovirt.engine.api.restapi.resource.SingleEntityResource; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.queries.GetHostListFromExternalProviderParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanHostsResource + extends AbstractBackendCollectionResource<ForemanHost, VDS> + implements ForemanHostsResource { + /** + * The identifier of the provider. + */ + private String providerId; + + public BackendForemanHostsResource(String providerId) { + super(ForemanHost.class, VDS.class); + this.providerId = providerId; + } + + @Override + public ForemanHosts list() { + GetHostListFromExternalProviderParameters parameters = new GetHostListFromExternalProviderParameters(); + parameters.setFilterOutExistingHosts(true); + parameters.setProviderId(asGuid(providerId)); + return mapCollection(getBackendCollection(VdcQueryType.GetHostListFromExternalProvider, parameters)); + } + + @Override + protected ForemanHost doPopulate(ForemanHost model, VDS entity) { + return model; + } + + protected ForemanHosts mapCollection(List<VDS> entities) { + ForemanHosts collection = new ForemanHosts(); + for (VDS entity : entities) { + collection.getForemanHosts().add(addLinks(populate(map(entity), entity))); + } + return collection; + } + + @Override + protected ForemanHost addParents(ForemanHost image) { + ForemanHostProvider provider = new ForemanHostProvider(); + provider.setId(providerId); + image.setForemanHostProvider(provider); + return super.addParents(image); + } + + @Override + protected Response performRemove(String id) { + throw new UnsupportedOperationException(); + } + + @Override + @SingleEntityResource + public ForemanHostResource getForemanHost(String id) { + return inject(new BackendForemanHostResource(id, providerId)); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java index 9868ddb..caf6780 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java @@ -126,7 +126,8 @@ "schedulingpolicyunits", "schedulingpolicies", "permissions", - "macpools" + "macpools", + "foremanhostproviders", }; private static final String[] relationshipsGlusterOnly = { @@ -188,7 +189,8 @@ BASE_PATH + "/schedulingpolicyunits", BASE_PATH + "/schedulingpolicies", BASE_PATH + "/permissions", - BASE_PATH + "/macpools" + BASE_PATH + "/macpools", + BASE_PATH + "/foremanhostproviders", }; private static final String[] hrefsGlusterOnly = { diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResourceTest.java new file mode 100644 index 0000000..ba929bd --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourceResourceTest.java @@ -0,0 +1,119 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import javax.ws.rs.WebApplicationException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest; +import org.ovirt.engine.core.common.businessentities.ExternalComputeResource; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanComputeResourceResourceTest + extends AbstractBackendSubResourceTest<ForemanComputeResource, ExternalComputeResource, BackendForemanComputeResourceResource> { + public BackendForemanComputeResourceResourceTest() { + super(new BackendForemanComputeResourceResource(string2hex(NAMES[1]), GUIDS[0].toString())); + } + + @Test + public void testBadId() throws Exception { + control.replay(); + try { + new BackendForemanHostProviderResource("foo"); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGetNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(true); + control.replay(); + try { + resource.get(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGet() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(false); + control.replay(); + verifyModel(resource.get(), 1); + } + + private Provider getProvider() { + Provider provider = control.createMock(Provider.class); + expect(provider.getId()).andReturn(GUIDS[0]).anyTimes(); + expect(provider.getName()).andReturn(NAMES[0]).anyTimes(); + return provider; + } + + private List<ExternalComputeResource> getResources() { + List<ExternalComputeResource> resources = new ArrayList<>(); + for (int i = 0; i < NAMES.length; i++) { + resources.add(getEntity(i)); + } + return resources; + } + + @Override + protected ExternalComputeResource getEntity(int index) { + ExternalComputeResource resource = control.createMock(ExternalComputeResource.class); + expect(resource.getName()).andReturn(NAMES[index]).anyTimes(); + return resource; + } + + private void setUpGetEntityExpectations(boolean notFound) throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetProviderById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + getProvider() + ); + setUpGetEntityExpectations( + VdcQueryType.GetComputeResourceFromExternalProvider, + ProviderQueryParameters.class, + new String[] { "Provider.Id" }, + new Object[] { GUIDS[0] }, + notFound? null: getResources() + ); + } + + @Override + protected void verifyModel(ForemanComputeResource model, int index) { + assertEquals(NAMES[index], model.getName()); + verifyLinks(model); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResourceTest.java new file mode 100644 index 0000000..9a5917d --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanComputeResourcesResourceTest.java @@ -0,0 +1,94 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; + +import java.util.ArrayList; +import java.util.List; + +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest; +import org.ovirt.engine.core.common.businessentities.ExternalComputeResource; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanComputeResourcesResourceTest extends + AbstractBackendCollectionResourceTest<ForemanComputeResource, ExternalComputeResource, BackendForemanComputeResourcesResource> { + public BackendForemanComputeResourcesResourceTest() { + super( + new BackendForemanComputeResourcesResource(GUIDS[0].toString()), + null, + "" + ); + } + + @Override + protected List<ForemanComputeResource> getCollection() { + return collection.list().getForemanComputeResources(); + } + + @Override + protected void setUpQueryExpectations(String query, Object failure) throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetProviderById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + getProvider() + ); + setUpEntityQueryExpectations( + VdcQueryType.GetComputeResourceFromExternalProvider, + ProviderQueryParameters.class, + new String[] { "Provider.Id" }, + new Object[] { GUIDS[0] }, + getResources(), + failure + ); + control.replay(); + } + + private Provider getProvider() { + Provider provider = control.createMock(Provider.class); + expect(provider.getId()).andReturn(GUIDS[0]).anyTimes(); + expect(provider.getName()).andReturn(NAMES[0]).anyTimes(); + return provider; + } + + private List<ExternalComputeResource> getResources() { + List<ExternalComputeResource> resources = new ArrayList<>(); + for (int i = 0; i < NAMES.length; i++) { + resources.add(getEntity(i)); + } + return resources; + } + + @Override + protected ExternalComputeResource getEntity(int index) { + ExternalComputeResource resource = control.createMock(ExternalComputeResource.class); + expect(resource.getName()).andReturn(NAMES[index]).anyTimes(); + return resource; + } + + @Override + protected void verifyModel(ForemanComputeResource model, int index) { + assertEquals(NAMES[index], model.getName()); + verifyLinks(model); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResourceTest.java new file mode 100644 index 0000000..9b61eb4 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupResourceTest.java @@ -0,0 +1,119 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import javax.ws.rs.WebApplicationException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest; +import org.ovirt.engine.core.common.businessentities.ExternalHostGroup; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanHostGroupResourceTest + extends AbstractBackendSubResourceTest<ForemanHostGroup, ExternalHostGroup, BackendForemanHostGroupResource> { + public BackendForemanHostGroupResourceTest() { + super(new BackendForemanHostGroupResource(string2hex(NAMES[1]), GUIDS[0].toString())); + } + + @Test + public void testBadId() throws Exception { + control.replay(); + try { + new BackendForemanHostProviderResource("foo"); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGetNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(true); + control.replay(); + try { + resource.get(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGet() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(false); + control.replay(); + verifyModel(resource.get(), 1); + } + + private Provider getProvider() { + Provider provider = control.createMock(Provider.class); + expect(provider.getId()).andReturn(GUIDS[0]).anyTimes(); + expect(provider.getName()).andReturn(NAMES[0]).anyTimes(); + return provider; + } + + private List<ExternalHostGroup> getGroups() { + List<ExternalHostGroup> groups = new ArrayList<>(); + for (int i = 0; i < NAMES.length; i++) { + groups.add(getEntity(i)); + } + return groups; + } + + @Override + protected ExternalHostGroup getEntity(int index) { + ExternalHostGroup group = control.createMock(ExternalHostGroup.class); + expect(group.getName()).andReturn(NAMES[index]).anyTimes(); + return group; + } + + private void setUpGetEntityExpectations(boolean notFound) throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetProviderById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + getProvider() + ); + setUpGetEntityExpectations( + VdcQueryType.GetHostGroupsFromExternalProvider, + ProviderQueryParameters.class, + new String[] { "Provider.Id" }, + new Object[] { GUIDS[0] }, + notFound? null: getGroups() + ); + } + + @Override + protected void verifyModel(ForemanHostGroup model, int index) { + assertEquals(NAMES[index], model.getName()); + verifyLinks(model); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResourceTest.java new file mode 100644 index 0000000..b80b0b3 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostGroupsResourceTest.java @@ -0,0 +1,94 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; + +import java.util.ArrayList; +import java.util.List; + +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest; +import org.ovirt.engine.core.common.businessentities.ExternalHostGroup; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.ProviderQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanHostGroupsResourceTest extends + AbstractBackendCollectionResourceTest<ForemanHostGroup, ExternalHostGroup, BackendForemanHostGroupsResource> { + public BackendForemanHostGroupsResourceTest() { + super( + new BackendForemanHostGroupsResource(GUIDS[0].toString()), + null, + "" + ); + } + + @Override + protected List<ForemanHostGroup> getCollection() { + return collection.list().getForemanHostGroups(); + } + + @Override + protected void setUpQueryExpectations(String query, Object failure) throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetProviderById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + getProvider() + ); + setUpEntityQueryExpectations( + VdcQueryType.GetHostGroupsFromExternalProvider, + ProviderQueryParameters.class, + new String[] { "Provider.Id" }, + new Object[] { GUIDS[0] }, + getGroups(), + failure + ); + control.replay(); + } + + private Provider getProvider() { + Provider provider = control.createMock(Provider.class); + expect(provider.getId()).andReturn(GUIDS[0]).anyTimes(); + expect(provider.getName()).andReturn(NAMES[0]).anyTimes(); + return provider; + } + + private List<ExternalHostGroup> getGroups() { + List<ExternalHostGroup> groups = new ArrayList<>(); + for (int i = 0; i < NAMES.length; i++) { + groups.add(getEntity(i)); + } + return groups; + } + + @Override + protected ExternalHostGroup getEntity(int index) { + ExternalHostGroup group = control.createMock(ExternalHostGroup.class); + expect(group.getName()).andReturn(NAMES[index]).anyTimes(); + return group; + } + + @Override + protected void verifyModel(ForemanHostGroup model, int index) { + assertEquals(NAMES[index], model.getName()); + verifyLinks(model); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResourceTest.java new file mode 100644 index 0000000..d7e5442 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProviderResourceTest.java @@ -0,0 +1,179 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; + +import javax.ws.rs.WebApplicationException; + +import org.junit.Test; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest; +import org.ovirt.engine.core.common.action.ProviderParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanHostProviderResourceTest + extends AbstractBackendSubResourceTest<ForemanHostProvider, Provider, BackendForemanHostProviderResource> { + public BackendForemanHostProviderResourceTest() { + super(new BackendForemanHostProviderResource(GUIDS[0].toString())); + } + + @Test + public void testBadGuid() throws Exception { + control.replay(); + try { + new BackendForemanHostProviderResource("foo"); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGetNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(1, true); + control.replay(); + try { + resource.get(); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGet() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(1); + control.replay(); + verifyModel(resource.get(), 0); + } + + @Test + public void testUpdateNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(1, true); + control.replay(); + try { + resource.update(getModel(0)); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testUpdate() throws Exception { + setUpGetEntityExpectations(2); + setUriInfo( + setUpActionExpectations( + VdcActionType.UpdateProvider, + ProviderParameters.class, + new String[] { "Provider.Id" }, + new Object[] { GUIDS[0] }, + true, + true + ) + ); + verifyModel(resource.update(getModel(0)), 0); + } + + @Test + public void testUpdateCantDo() throws Exception { + doTestBadUpdate(false, true, CANT_DO); + } + + @Test + public void testUpdateFailed() throws Exception { + doTestBadUpdate(true, false, FAILURE); + } + + private void doTestBadUpdate(boolean canDo, boolean success, String detail) throws Exception { + setUpGetEntityExpectations(1); + setUriInfo( + setUpActionExpectations( + VdcActionType.UpdateProvider, + ProviderParameters.class, + new String[] { "Provider.Id" }, + new Object[] { GUIDS[0] }, + canDo, + success + ) + ); + try { + resource.update(getModel(0)); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyFault(wae, detail); + } + } + + @Test + public void testConflictedUpdate() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(1); + control.replay(); + + ForemanHostProvider model = getModel(1); + model.setId(GUIDS[1].toString()); + try { + resource.update(model); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyImmutabilityConstraint(wae); + } + } + + private ForemanHostProvider getModel(int index) { + ForemanHostProvider model = new ForemanHostProvider(); + model.setName(NAMES[index]); + model.setDescription(DESCRIPTIONS[index]); + return model; + } + + @Override + protected Provider getEntity(int index) { + Provider provider = control.createMock(Provider.class); + expect(provider.getId()).andReturn(GUIDS[index]).anyTimes(); + expect(provider.getName()).andReturn(NAMES[index]).anyTimes(); + expect(provider.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes(); + return provider; + } + + protected void setUpGetEntityExpectations(int times) throws Exception { + setUpGetEntityExpectations(times, false); + } + + protected void setUpGetEntityExpectations(int times, boolean notFound) throws Exception { + while (times-- > 0) { + setUpGetEntityExpectations( + VdcQueryType.GetProviderById, + IdQueryParameters.class, + new String[] { "Id" }, + new Object[] { GUIDS[0] }, + notFound? null: getEntity(0) + ); + } + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResourceTest.java new file mode 100644 index 0000000..f90f370 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostProvidersResourceTest.java @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; + +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.businessentities.ProviderType; +import org.ovirt.engine.core.common.interfaces.SearchType; + +public class BackendForemanHostProvidersResourceTest extends + AbstractBackendCollectionResourceTest<ForemanHostProvider, Provider, BackendForemanHostProvidersResource> { + + public BackendForemanHostProvidersResourceTest() { + super( + new BackendForemanHostProvidersResource(), + SearchType.Provider, + "Providers: type=" + ProviderType.FOREMAN.name() + ); + } + + @Override + protected List<ForemanHostProvider> getCollection() { + return collection.list().getForemanHostProviders(); + } + + @Override + protected void setUpQueryExpectations(String query) throws Exception { + if (StringUtils.isNotBlank(query)) { + query = " AND (" + query + ")"; + } + super.setUpQueryExpectations(query); + } + + @Override + protected Provider getEntity(int index) { + Provider provider = control.createMock(Provider.class); + expect(provider.getId()).andReturn(GUIDS[index]).anyTimes(); + expect(provider.getName()).andReturn(NAMES[index]).anyTimes(); + expect(provider.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes(); + return provider; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResourceTest.java new file mode 100644 index 0000000..7e7aa4c --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostResourceTest.java @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import javax.ws.rs.WebApplicationException; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.queries.GetHostListFromExternalProviderParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanHostResourceTest + extends AbstractBackendSubResourceTest<ForemanHost, VDS, BackendForemanHostResource> { + public BackendForemanHostResourceTest() { + super(new BackendForemanHostResource(string2hex(NAMES[1]), GUIDS[0].toString())); + } + + @Test + public void testBadId() throws Exception { + control.replay(); + try { + new BackendForemanHostProviderResource("foo"); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGetNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(true); + control.replay(); + try { + resource.get(); + fail("expected WebApplicationException"); + } + catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGet() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(false); + control.replay(); + verifyModel(resource.get(), 1); + } + + private List<VDS> getHosts() { + List<VDS> hosts = new ArrayList<>(); + for (int i = 0; i < NAMES.length; i++) { + hosts.add(getEntity(i)); + } + return hosts; + } + + @Override + protected VDS getEntity(int index) { + VDS provider = control.createMock(VDS.class); + expect(provider.getId()).andReturn(GUIDS[index]).anyTimes(); + expect(provider.getName()).andReturn(NAMES[index]).anyTimes(); + return provider; + } + + private void setUpGetEntityExpectations(boolean notFound) throws Exception { + setUpGetEntityExpectations( + VdcQueryType.GetHostListFromExternalProvider, + GetHostListFromExternalProviderParameters.class, + new String[] { "ProviderId" }, + new Object[] { GUIDS[0] }, + notFound? null: getHosts() + ); + } + + @Override + protected void verifyModel(ForemanHost model, int index) { + assertEquals(NAMES[index], model.getName()); + verifyLinks(model); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResourceTest.java new file mode 100644 index 0000000..0d47831 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/foreman/BackendForemanHostsResourceTest.java @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.resource.foreman; + +import static org.easymock.EasyMock.expect; + +import java.util.ArrayList; +import java.util.List; + +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.queries.GetHostListFromExternalProviderParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendForemanHostsResourceTest extends + AbstractBackendCollectionResourceTest<ForemanHost, VDS, BackendForemanHostsResource> { + public BackendForemanHostsResourceTest() { + super( + new BackendForemanHostsResource(GUIDS[0].toString()), + null, + "" + ); + } + + @Override + protected List<ForemanHost> getCollection() { + return collection.list().getForemanHosts(); + } + + @Override + protected void setUpQueryExpectations(String query, Object failure) throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetHostListFromExternalProvider, + GetHostListFromExternalProviderParameters.class, + new String[] { "ProviderId" }, + new Object[] { GUIDS[0] }, + getHosts(), + failure + ); + control.replay(); + } + + private List<VDS> getHosts() { + List<VDS> hosts = new ArrayList<>(); + for (int i = 0; i < NAMES.length; i++) { + hosts.add(getEntity(i)); + } + return hosts; + } + + @Override + protected VDS getEntity(int index) { + VDS host = control.createMock(VDS.class); + expect(host.getId()).andReturn(GUIDS[index]).anyTimes(); + expect(host.getName()).andReturn(NAMES[index]).anyTimes(); + return host; + } + + @Override + protected void verifyModel(ForemanHost model, int index) { + assertEquals(NAMES[index], model.getName()); + verifyLinks(model); + } +} diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapper.java new file mode 100644 index 0000000..6f21ad2 --- /dev/null +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapper.java @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.restapi.types.Mapping; +import org.ovirt.engine.core.common.businessentities.ExternalComputeResource; + +public class ForemanComputeResourceMapper { + @Mapping(from = ExternalComputeResource.class, to = ForemanComputeResource.class) + public static ForemanComputeResource map(ExternalComputeResource entity, ForemanComputeResource template) { + ForemanComputeResource model = template != null ? template : new ForemanComputeResource(); + String name = entity.getName(); + if (name != null) { + model.setId(string2hex(name)); + model.setName(name); + } + return model; + } + + @Mapping(from = ForemanComputeResource.class, to = ExternalComputeResource.class) + public static ExternalComputeResource map(ForemanComputeResource model, ExternalComputeResource template) { + ExternalComputeResource entity = template != null ? template : new ExternalComputeResource(); + if (model.isSetId()) { + entity.setName(hex2string(model.getId())); + } + else if (model.isSetName()) { + entity.setName(model.getName()); + } + return entity; + } +} diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapper.java new file mode 100644 index 0000000..1ff6aef --- /dev/null +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapper.java @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.restapi.types.Mapping; +import org.ovirt.engine.core.common.businessentities.ExternalHostGroup; + +public class ForemanHostGroupMapper { + @Mapping(from = ExternalHostGroup.class, to = ForemanHostGroup.class) + public static ForemanHostGroup map(ExternalHostGroup entity, ForemanHostGroup template) { + ForemanHostGroup model = template != null? template: new ForemanHostGroup(); + String name = entity.getName(); + if (name != null) { + model.setId(string2hex(name)); + model.setName(name); + } + return model; + } + + @Mapping(from = ForemanHostGroup.class, to = ExternalHostGroup.class) + public static ExternalHostGroup map(ForemanHostGroup model, ExternalHostGroup template) { + ExternalHostGroup entity = template != null? template: new ExternalHostGroup(); + if (model.isSetId()) { + entity.setName(hex2string(model.getId())); + } + else if (model.isSetName()) { + entity.setName(model.getName()); + } + return entity; + } +} diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapper.java new file mode 100644 index 0000000..c0b194d --- /dev/null +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapper.java @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.restapi.types.Mapping; +import org.ovirt.engine.core.common.businessentities.VDS; + +public class ForemanHostMapper { + @Mapping(from = VDS.class, to = ForemanHost.class) + public static ForemanHost map(VDS entity, ForemanHost template) { + ForemanHost model = template != null ? template : new ForemanHost(); + String name = entity.getName(); + if (name != null) { + model.setId(string2hex(name)); + model.setName(name); + } + if (entity.getHostName() != null) { + model.setAddress(entity.getHostName()); + } + return model; + } + + @Mapping(from = ForemanHost.class, to = VDS.class) + public static VDS map(ForemanHost model, VDS template) { + VDS entity = template != null ? template : new VDS(); + if (model.isSetId()) { + entity.setVdsName(hex2string(model.getId())); + } + else if (model.isSetName()) { + entity.setVdsName(model.getName()); + } + if (model.isSetAddress()) { + entity.setHostName(model.getAddress()); + } + return entity; + } +} diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapper.java new file mode 100644 index 0000000..3b3ad07 --- /dev/null +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapper.java @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import java.util.HashMap; +import java.util.Map; + +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.model.Properties; +import org.ovirt.engine.api.model.Property; +import org.ovirt.engine.api.restapi.types.Mapping; +import org.ovirt.engine.api.restapi.utils.GuidUtils; +import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.businessentities.ProviderType; + +public class ForemanHostProviderMapper { + @Mapping(from = ForemanHostProvider.class, to = Provider.class) + public static Provider map(ForemanHostProvider model, Provider template) { + Provider entity = template != null? template: new Provider(); + entity.setType(ProviderType.FOREMAN); + if (model.isSetId()) { + entity.setId(GuidUtils.asGuid(model.getId())); + } + if (model.isSetName()) { + entity.setName(model.getName()); + } + if (model.isSetDescription()) { + entity.setDescription(model.getDescription()); + } + if (model.isSetUrl()) { + entity.setUrl(model.getUrl()); + } + if (model.isSetRequiresAuthentication()) { + entity.setRequiringAuthentication(model.isRequiresAuthentication()); + } + if (model.isSetUsername()) { + entity.setUsername(model.getUsername()); + } + if (model.isSetPassword()) { + entity.setPassword(model.getPassword()); + } + if (model.isSetProperties()) { + Map<String, String> map = new HashMap<>(); + for (Property property : model.getProperties().getProperties()) { + map.put(property.getName(), property.getValue()); + } + entity.setCustomProperties(map); + } + return entity; + } + + @Mapping(from = Provider.class, to = ForemanHostProvider.class) + public static ForemanHostProvider map(Provider entity, ForemanHostProvider template) { + ForemanHostProvider model = template != null? template: new ForemanHostProvider(); + if (entity.getId() != null) { + model.setId(entity.getId().toString()); + } + if (entity.getName() != null) { + model.setName(entity.getName()); + } + if (entity.getDescription() != null) { + model.setDescription(entity.getDescription()); + } + if (entity.getUrl() != null) { + model.setUrl(entity.getUrl()); + } + model.setRequiresAuthentication(entity.isRequiringAuthentication()); + if (entity.getUsername() != null) { + model.setUsername(entity.getUsername()); + } + // The password isn't mapped for security reasons. + // if (entity.getPassword() != null) { + // model.setPassword(entity.getPassword()); + // } + Map<String, String> customProperties = entity.getCustomProperties(); + if (customProperties != null) { + Properties properties = new Properties(); + for (Map.Entry<String, String> entry : customProperties.entrySet()) { + Property property = new Property(); + property.setName(entry.getKey()); + property.setValue(entry.getValue()); + properties.getProperties().add(property); + } + model.setProperties(properties); + } + return model; + } +} diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapperTest.java new file mode 100644 index 0000000..ec94f70 --- /dev/null +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanComputeResourceMapperTest.java @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import org.ovirt.engine.api.model.ForemanComputeResource; +import org.ovirt.engine.api.restapi.types.AbstractInvertibleMappingTest; +import org.ovirt.engine.core.common.businessentities.ExternalComputeResource; + +public class ForemanComputeResourceMapperTest + extends AbstractInvertibleMappingTest<ForemanComputeResource, ExternalComputeResource, ExternalComputeResource> { + public ForemanComputeResourceMapperTest() { + super(ForemanComputeResource.class, ExternalComputeResource.class, ExternalComputeResource.class); + } + + @Override + protected ForemanComputeResource postPopulate(ForemanComputeResource model) { + // The id is expected to be the name encoded in hex: + model.setId(string2hex(model.getName())); + return model; + } + + @Override + protected void verify(ForemanComputeResource model, ForemanComputeResource transform) { + assertNotNull(transform); + assertEquals(model.getId(), transform.getId()); + assertEquals(model.getName(), transform.getName()); + } +} diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapperTest.java new file mode 100644 index 0000000..9ed777a --- /dev/null +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostGroupMapperTest.java @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import org.ovirt.engine.api.model.ForemanHostGroup; +import org.ovirt.engine.api.restapi.types.AbstractInvertibleMappingTest; +import org.ovirt.engine.core.common.businessentities.ExternalHostGroup; + +public class ForemanHostGroupMapperTest + extends AbstractInvertibleMappingTest<ForemanHostGroup, ExternalHostGroup, ExternalHostGroup> { + public ForemanHostGroupMapperTest() { + super(ForemanHostGroup.class, ExternalHostGroup.class, ExternalHostGroup.class); + } + + @Override + protected ForemanHostGroup postPopulate(ForemanHostGroup model) { + // The id is expected to be the name encoded in hex: + model.setId(string2hex(model.getName())); + return model; + } + + @Override + protected void verify(ForemanHostGroup model, ForemanHostGroup transform) { + assertNotNull(transform); + assertEquals(model.getId(), transform.getId()); + assertEquals(model.getName(), transform.getName()); + } +} diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapperTest.java new file mode 100644 index 0000000..d60a107 --- /dev/null +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostMapperTest.java @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import org.ovirt.engine.api.model.ForemanHost; +import org.ovirt.engine.api.restapi.types.AbstractInvertibleMappingTest; +import org.ovirt.engine.core.common.businessentities.VDS; + +public class ForemanHostMapperTest + extends AbstractInvertibleMappingTest<ForemanHost, VDS, VDS> { + public ForemanHostMapperTest() { + super(ForemanHost.class, VDS.class, VDS.class); + } + + @Override + protected ForemanHost postPopulate(ForemanHost model) { + // The id is expected to be the name encoded in hex: + model.setId(string2hex(model.getName())); + return model; + } + + @Override + protected void verify(ForemanHost model, ForemanHost transform) { + assertNotNull(transform); + assertEquals(model.getId(), transform.getId()); + assertEquals(model.getName(), transform.getName()); + assertEquals(model.getAddress(), transform.getAddress()); + } +} diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapperTest.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapperTest.java new file mode 100644 index 0000000..b1c2ef0 --- /dev/null +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/foreman/ForemanHostProviderMapperTest.java @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.restapi.types.foreman; + +import org.ovirt.engine.api.model.ForemanHostProvider; +import org.ovirt.engine.api.restapi.types.AbstractInvertibleMappingTest; +import org.ovirt.engine.core.common.businessentities.Provider; + +public class ForemanHostProviderMapperTest + extends AbstractInvertibleMappingTest<ForemanHostProvider, Provider, Provider> { + public ForemanHostProviderMapperTest() { + super(ForemanHostProvider.class, Provider.class, Provider.class); + } + + @Override + protected void verify(ForemanHostProvider model, ForemanHostProvider transform) { + assertNotNull(transform); + assertEquals(model.getId(), transform.getId()); + assertEquals(model.getName(), transform.getName()); + assertEquals(model.getDescription(), transform.getDescription()); + assertEquals(model.isRequiresAuthentication(), transform.isRequiresAuthentication()); + assertEquals(model.getUrl(), transform.getUrl()); + assertEquals(model.getUsername(), transform.getUsername()); + // The password isn't mapped for security reasons. + assertNull(transform.getPassword()); + } +} -- To view, visit http://gerrit.ovirt.org/33969 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2144125f00822263dc68da881eb3180c4cd6b237 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches