Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Add collection for operating systems
......................................................................

restapi: Add collection for operating systems

This patch adds a new top level "operatingsystems" read only collection:

  GET /operatingsystems
  <operating_systems>
    <operating_system id="0">
      <name>other</name>
      <description>Other OS</description>
    </operating_system>
    ...
  </operating_systems>

  GET /operatingsystems/0
  <operating_system id="0">
    <name>other</name>
    <description>Other OS</description>
  </operating_system>

Change-Id: Ibae9977a6fbfc8728ee66e705f0594f230ff47ba
Bug-Url: https://bugzilla.redhat.com/1050243
Signed-off-by: Juan Hernandez <[email protected]>
---
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemResource.java
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemsResource.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/BackendOperatingSystemResource.java
A 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendOperatingSystemsResource.java
9 files changed, 253 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/25/34225/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemResource.java
new file mode 100644
index 0000000..591b544
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemResource.java
@@ -0,0 +1,28 @@
+/*
+* 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;
+
+import org.ovirt.engine.api.model.OperatingSystemInfo;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+public interface OperatingSystemResource {
+    @GET
+    public OperatingSystemInfo get();
+}
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemsResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemsResource.java
new file mode 100644
index 0000000..5159cd0
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/OperatingSystemsResource.java
@@ -0,0 +1,34 @@
+/*
+* 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;
+
+import org.ovirt.engine.api.model.OperatingSystemInfos;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+@Path("/operatingsystems")
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+public interface OperatingSystemsResource {
+    @GET
+    public OperatingSystemInfos list();
+
+    @Path("{id}")
+    public OperatingSystemResource getOperatingSystem(@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..a175124 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("operatingsystems", 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..1ce8f72 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
@@ -66,6 +66,7 @@
 import org.ovirt.engine.api.model.NIC;
 import org.ovirt.engine.api.model.Network;
 import org.ovirt.engine.api.model.NumaNode;
+import org.ovirt.engine.api.model.OperatingSystemInfo;
 import org.ovirt.engine.api.model.Parameter;
 import org.ovirt.engine.api.model.ParametersSet;
 import org.ovirt.engine.api.model.Permission;
@@ -155,6 +156,8 @@
 import org.ovirt.engine.api.resource.MovableCopyableDiskResource;
 import org.ovirt.engine.api.resource.NetworkResource;
 import org.ovirt.engine.api.resource.NetworksResource;
+import org.ovirt.engine.api.resource.OperatingSystemResource;
+import org.ovirt.engine.api.resource.OperatingSystemsResource;
 import org.ovirt.engine.api.resource.PermissionResource;
 import org.ovirt.engine.api.resource.PermitResource;
 import org.ovirt.engine.api.resource.PermitsResource;
@@ -479,6 +482,9 @@
         map = new ParentToCollectionMap(CpuProfileResource.class, 
CpuProfilesResource.class);
         TYPES.put(CpuProfile.class, map);
 
+        // Operating systems:
+        map = new ParentToCollectionMap(OperatingSystemResource.class, 
OperatingSystemsResource.class);
+        TYPES.put(OperatingSystemInfo.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 b4c6662..e3159e2 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
@@ -4914,4 +4914,32 @@
       </xs:extension>
     </xs:complexContent>
   </xs:complexType>
+
+  <!-- Operating systems: -->
+  <xs:element name="operating_system" type="OperatingSystemInfo"/>
+
+  <xs:element name="operating_systems" type="OperatingSystemInfos"/>
+
+  <xs:complexType name="OperatingSystemInfo">
+    <xs:complexContent>
+      <xs:extension base="BaseResource"/>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:complexType name="OperatingSystemInfos">
+    <xs:complexContent>
+      <xs:extension base="BaseResources">
+        <xs:sequence>
+          <xs:element ref="operating_system" minOccurs="0" 
maxOccurs="unbounded">
+            <xs:annotation>
+              <xs:appinfo>
+                <jaxb:property name="OperatingSystemInfos"/>
+              </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 76198c1..b135f5c 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
@@ -6136,3 +6136,20 @@
       Content-Type: {value: application/xml|json, required: true}
       Expect: {value: 201-created, required: false}
       Correlation-Id: {value: 'any string', required: false}
+
+- name: /operatingsystems|rel=get
+  description: get the list of all Operating Systems
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams: {}
+    headers: {}
+- name: /operatingsystems/{operatingsystem:id}|rel=get
+  description: get the details of the specified Operating System
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams: {}
+    headers: {}
\ No newline at end of file
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 3fcdd38..6612432 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
@@ -41,6 +41,7 @@
 import org.ovirt.engine.api.restapi.resource.BackendJobsResource;
 import org.ovirt.engine.api.restapi.resource.BackendMacPoolsResource;
 import org.ovirt.engine.api.restapi.resource.BackendNetworksResource;
+import org.ovirt.engine.api.restapi.resource.BackendOperatingSystemsResource;
 import org.ovirt.engine.api.restapi.resource.BackendResource;
 import org.ovirt.engine.api.restapi.resource.BackendRolesResource;
 import org.ovirt.engine.api.restapi.resource.BackendSchedulingPoliciesResource;
@@ -146,6 +147,7 @@
         addResource(new BackendSystemPermissionsResource());
         addResource(new BackendDiskProfilesResource());
         addResource(new BackendCpuProfilesResource());
+        addResource(new BackendOperatingSystemsResource());
 
         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/BackendOperatingSystemResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendOperatingSystemResource.java
new file mode 100644
index 0000000..c52f983
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendOperatingSystemResource.java
@@ -0,0 +1,60 @@
+/*
+* 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;
+
+import org.ovirt.engine.api.model.OperatingSystemInfo;
+import org.ovirt.engine.api.resource.OperatingSystemResource;
+import org.ovirt.engine.core.common.osinfo.OsRepository;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendOperatingSystemResource
+        extends AbstractBackendSubResource<OperatingSystemInfo, Integer>
+        implements OperatingSystemResource {
+    public BackendOperatingSystemResource(String id) {
+        super(id, OperatingSystemInfo.class, Integer.class);
+    }
+
+    @Override
+    public OperatingSystemInfo get() {
+        OsRepository repository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
+        OperatingSystemInfo model = new OperatingSystemInfo();
+        model.setId(id);
+        Integer key = Integer.valueOf(id);
+        String uniqueName = repository.getUniqueOsNames().get(key);
+        if (uniqueName == null) {
+            return notFound();
+        }
+        model.setName(uniqueName);
+        String name = repository.getOsNames().get(key);
+        if (name != null) {
+            model.setDescription(name);
+        }
+        return addLinks(model);
+    }
+
+    @Override
+    protected OperatingSystemInfo doPopulate(OperatingSystemInfo model, 
Integer entity) {
+        return model;
+    }
+
+    @Override
+    protected Guid asGuidOr404(String id) {
+        // The identifier if an operating system isn't a UUID.
+        return null;
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendOperatingSystemsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendOperatingSystemsResource.java
new file mode 100644
index 0000000..cc7a824
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendOperatingSystemsResource.java
@@ -0,0 +1,77 @@
+/*
+* 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;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.ovirt.engine.api.model.OperatingSystemInfo;
+import org.ovirt.engine.api.model.OperatingSystemInfos;
+import org.ovirt.engine.api.resource.OperatingSystemResource;
+import org.ovirt.engine.api.resource.OperatingSystemsResource;
+import org.ovirt.engine.core.common.osinfo.OsRepository;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
+
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+
+public class BackendOperatingSystemsResource
+        extends AbstractBackendCollectionResource<OperatingSystemInfo, Integer>
+        implements OperatingSystemsResource {
+    public BackendOperatingSystemsResource() {
+        super(OperatingSystemInfo.class, Integer.class);
+    }
+
+    @Override
+    public OperatingSystemInfos list() {
+        OsRepository repository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
+        ArrayList<Integer> ids = repository.getOsIds();
+        HashMap<Integer, String> uniqueNames = repository.getUniqueOsNames();
+        HashMap<Integer, String> names = repository.getOsNames();
+        OperatingSystemInfos collection = new OperatingSystemInfos();
+        for (Integer id : ids) {
+            OperatingSystemInfo model = new OperatingSystemInfo();
+            model.setId(id.toString());
+            String uniqueName = uniqueNames.get(id);
+            if (uniqueName != null) {
+                model.setName(uniqueName);
+            }
+            String name = names.get(id);
+            if (name != null) {
+                model.setDescription(name);
+            }
+            collection.getOperatingSystemInfos().add(addLinks(model));
+        }
+        return collection;
+    }
+
+    @Override
+    @SingleEntityResource
+    public OperatingSystemResource getOperatingSystem(String id) {
+        return inject(new BackendOperatingSystemResource(id));
+    }
+
+    @Override
+    protected OperatingSystemInfo doPopulate(OperatingSystemInfo model, 
Integer entity) {
+        return model;
+    }
+
+    @Override
+    protected Response performRemove(String id) {
+        throw new NotImplementedException();
+    }
+}


-- 
To view, visit http://gerrit.ovirt.org/34225
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibae9977a6fbfc8728ee66e705f0594f230ff47ba
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to