Daniel Erez has uploaded a new change for review.

Change subject: restapi: CRUD for OpenStackVolume authentication keys
......................................................................

restapi: CRUD for OpenStackVolume authentication keys

Added AuthenticationKeys sub-collection to OpenStackNetworkProviders
root collection. Supported actions: list/get/add/update/remove.
See detailed information and examples in feature page.

Feature Page: http://www.ovirt.org/Features/Cinder_Integration

Change-Id: I1041a9760c29919d86da5479ce29db666d18a924
Bug-Url: https://bugzilla.redhat.com/1185826
Signed-off-by: Daniel Erez <[email protected]>
---
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OpenstackVolumeAuthenticationKeyUsageType.java
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeyResource.java
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeysResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeProviderResource.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
A 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResource.java
A 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProviderResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProvidersResource.java
A 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/validation/OpenstackVolumeAuthenticationKeyValidator.java
A 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResourceTest.java
A 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResourceTest.java
A 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackVolumeAuthenticationKeyMapper.java
14 files changed, 683 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/69/41969/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OpenstackVolumeAuthenticationKeyUsageType.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OpenstackVolumeAuthenticationKeyUsageType.java
new file mode 100644
index 0000000..9786585
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/OpenstackVolumeAuthenticationKeyUsageType.java
@@ -0,0 +1,18 @@
+package org.ovirt.engine.api.model;
+
+public enum OpenstackVolumeAuthenticationKeyUsageType {
+
+    CEPH;
+
+    public String value() {
+        return name().toLowerCase();
+    }
+
+    public static OpenstackVolumeAuthenticationKeyUsageType fromValue(String 
v) {
+        try {
+            return valueOf(v.toUpperCase());
+        } catch (IllegalArgumentException e) {
+            return null;
+        }
+    }
+}
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeyResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeyResource.java
new file mode 100644
index 0000000..fa70474
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeyResource.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.openstack;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Produces;
+
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+import org.ovirt.engine.api.resource.ApiMediaType;
+
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+public interface OpenStackVolumeAuthenticationKeyResource {
+    @GET
+    public OpenstackVolumeAuthenticationKey get();
+
+    @PUT
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    public OpenstackVolumeAuthenticationKey 
update(OpenstackVolumeAuthenticationKey resource);
+}
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeysResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeysResource.java
new file mode 100644
index 0000000..9f5e854
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeAuthenticationKeysResource.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.openstack;
+
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKeys;
+import org.ovirt.engine.api.resource.ApiMediaType;
+
+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;
+
+@Path("authenticationkeys")
+@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+public interface OpenStackVolumeAuthenticationKeysResource {
+    @GET
+    public OpenstackVolumeAuthenticationKeys list();
+
+    @POST
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    public Response add(OpenstackVolumeAuthenticationKey authenticationKey);
+
+    @DELETE
+    @Path("{id}")
+    public Response remove(@PathParam("id") String id);
+
+    @Path("{id}")
+    OpenStackVolumeAuthenticationKeyResource 
getOpenStackVolumeAuthenticationKey(@PathParam("id") String id);
+}
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeProviderResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeProviderResource.java
index 4fb3b2f..23c1828 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeProviderResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/openstack/OpenStackVolumeProviderResource.java
@@ -27,4 +27,7 @@
 public interface OpenStackVolumeProviderResource extends 
ExternalProviderResource<OpenStackVolumeProvider> {
     @Path("volumetypes")
     public OpenStackVolumeTypesResource getOpenStackVolumeTypes();
+
+    @Path("authenticationkeys")
+    public OpenStackVolumeAuthenticationKeysResource 
getOpenStackVolumeAuthenticationKeys();
 }
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 f06ebd2..fd1808f 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
@@ -82,6 +82,7 @@
 import org.ovirt.engine.api.model.OpenStackSubnet;
 import org.ovirt.engine.api.model.OpenStackVolumeProvider;
 import org.ovirt.engine.api.model.OpenStackVolumeType;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
 import org.ovirt.engine.api.model.OperatingSystemInfo;
 import org.ovirt.engine.api.model.Parameter;
 import org.ovirt.engine.api.model.ParametersSet;
@@ -268,6 +269,8 @@
 import org.ovirt.engine.api.resource.openstack.OpenStackNetworksResource;
 import org.ovirt.engine.api.resource.openstack.OpenStackSubnetResource;
 import org.ovirt.engine.api.resource.openstack.OpenStackSubnetsResource;
+import 
org.ovirt.engine.api.resource.openstack.OpenStackVolumeAuthenticationKeyResource;
+import 
org.ovirt.engine.api.resource.openstack.OpenStackVolumeAuthenticationKeysResource;
 import org.ovirt.engine.api.resource.openstack.OpenStackVolumeProviderResource;
 import 
org.ovirt.engine.api.resource.openstack.OpenStackVolumeProvidersResource;
 import org.ovirt.engine.api.resource.openstack.OpenStackVolumeTypeResource;
@@ -570,6 +573,10 @@
         map.add(OpenStackVolumeTypeResource.class, 
OpenStackVolumeTypesResource.class, OpenStackVolumeProvider.class);
         TYPES.put(OpenStackVolumeType.class, map);
 
+        map = new 
ParentToCollectionMap(OpenStackVolumeAuthenticationKeyResource.class, 
OpenStackVolumeAuthenticationKeysResource.class);
+        map.add(OpenStackVolumeAuthenticationKeyResource.class, 
OpenStackVolumeAuthenticationKeysResource.class, OpenStackVolumeProvider.class);
+        TYPES.put(OpenstackVolumeAuthenticationKey.class, map);
+
         // OpenStack network providers:
         map = new 
ParentToCollectionMap(OpenStackNetworkProviderResource.class, 
OpenStackNetworkProvidersResource.class);
         TYPES.put(OpenStackNetworkProvider.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 8434cdf..60a9244 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
@@ -5480,6 +5480,40 @@
     </xs:complexContent>
   </xs:complexType>
 
+  <xs:element name="openstack_volume_authentication_key" 
type="OpenstackVolumeAuthenticationKey"/>
+
+  <xs:element name="openstack_volume_authentication_keys" 
type="OpenstackVolumeAuthenticationKeys"/>
+
+  <xs:complexType name="OpenstackVolumeAuthenticationKey">
+    <xs:complexContent>
+      <xs:extension base="BaseResource">
+        <xs:sequence>
+          <xs:element name="uuid" type="xs:string" minOccurs="0" 
maxOccurs="1"/>
+          <xs:element name="value" type="xs:string" minOccurs="0" 
maxOccurs="1"/>
+          <xs:element name="usage_type" type="xs:string" minOccurs="0" 
maxOccurs="1"/>
+          <xs:element name="creation_date" type="xs:dateTime" minOccurs="0" 
maxOccurs="1"/>
+          <xs:element ref="openstack_volume_provider" minOccurs="0" 
maxOccurs="1"/>
+        </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:complexType name="OpenstackVolumeAuthenticationKeys">
+    <xs:complexContent>
+      <xs:extension base="BaseResources">
+        <xs:sequence>
+          <xs:element ref="openstack_volume_authentication_key" minOccurs="0" 
maxOccurs="unbounded">
+            <xs:annotation>
+              <xs:appinfo>
+                <jaxb:property name="OpenstackVolumeAuthenticationKeys"/>
+              </xs:appinfo>
+            </xs:annotation>
+          </xs:element>
+        </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
   <!-- OpenStack network providers: -->
   <xs:element name="openstack_network_provider" 
type="OpenStackNetworkProvider"/>
 
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResource.java
new file mode 100644
index 0000000..7a1e0e6
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResource.java
@@ -0,0 +1,80 @@
+/*
+ * 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.openstack;
+
+import org.ovirt.engine.api.model.OpenStackVolumeProvider;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+import 
org.ovirt.engine.api.resource.openstack.OpenStackVolumeAuthenticationKeyResource;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource;
+import org.ovirt.engine.core.common.action.LibvirtSecretParameters;
+import org.ovirt.engine.core.common.action.VdcActionParametersBase;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+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 BackendOpenStackVolumeAuthenticationKeyResource
+        extends 
AbstractBackendActionableResource<OpenstackVolumeAuthenticationKey, 
LibvirtSecret>
+        implements OpenStackVolumeAuthenticationKeyResource {
+    private String providerId;
+    protected Guid guid;
+
+    protected BackendOpenStackVolumeAuthenticationKeyResource(String 
providerId, String id) {
+        super(id, OpenstackVolumeAuthenticationKey.class, LibvirtSecret.class);
+        this.providerId = providerId;
+        this.guid = asGuidOr404(id);
+    }
+
+    @Override
+    public OpenstackVolumeAuthenticationKey get() {
+        return performGet(VdcQueryType.GetLibvirtSecretById, new 
IdQueryParameters(guid));
+    }
+
+    @Override
+    public OpenstackVolumeAuthenticationKey 
update(OpenstackVolumeAuthenticationKey resource) {
+        validateEnums(OpenstackVolumeAuthenticationKey.class, resource);
+        return performUpdate(
+                resource,
+                new QueryIdResolver<Guid>(VdcQueryType.GetLibvirtSecretById, 
IdQueryParameters.class),
+                VdcActionType.UpdateLibvirtSecret,
+                new UpdateParametersProvider());
+    }
+
+    private class UpdateParametersProvider implements 
ParametersProvider<OpenstackVolumeAuthenticationKey, 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret> {
+        @Override
+        public VdcActionParametersBase 
getParameters(OpenstackVolumeAuthenticationKey model,
+                
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret entity) {
+            final 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret 
libvirtSecret =
+                    map(model, entity);
+            return new LibvirtSecretParameters(libvirtSecret);
+        }
+    }
+
+    @Override
+    protected OpenstackVolumeAuthenticationKey 
doPopulate(OpenstackVolumeAuthenticationKey model, LibvirtSecret entity) {
+        return model;
+    }
+
+    @Override
+    protected OpenstackVolumeAuthenticationKey 
addParents(OpenstackVolumeAuthenticationKey authenticationKey) {
+        OpenStackVolumeProvider provider = new OpenStackVolumeProvider();
+        provider.setId(providerId);
+        authenticationKey.setOpenstackVolumeProvider(provider);
+        return super.addParents(authenticationKey);
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResource.java
new file mode 100644
index 0000000..6e5a730
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResource.java
@@ -0,0 +1,104 @@
+/*
+* 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.openstack;
+
+import java.util.List;
+
+import javax.ws.rs.core.Response;
+
+import org.ovirt.engine.api.model.OpenStackVolumeProvider;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKeys;
+import 
org.ovirt.engine.api.resource.openstack.OpenStackVolumeAuthenticationKeyResource;
+import 
org.ovirt.engine.api.resource.openstack.OpenStackVolumeAuthenticationKeysResource;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource;
+import org.ovirt.engine.api.restapi.resource.SingleEntityResource;
+import org.ovirt.engine.api.restapi.utils.GuidUtils;
+import org.ovirt.engine.core.common.action.LibvirtSecretParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+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 BackendOpenStackVolumeAuthenticationKeysResource
+        extends 
AbstractBackendCollectionResource<OpenstackVolumeAuthenticationKey, 
LibvirtSecret>
+        implements OpenStackVolumeAuthenticationKeysResource {
+    private String providerId;
+
+    public BackendOpenStackVolumeAuthenticationKeysResource(String providerId) 
{
+        super(OpenstackVolumeAuthenticationKey.class, LibvirtSecret.class);
+        this.providerId = providerId;
+    }
+
+    @Override
+    public OpenstackVolumeAuthenticationKeys list() {
+        IdQueryParameters parameters = new 
IdQueryParameters(GuidUtils.asGuid(providerId));
+        return 
mapCollection(getBackendCollection(VdcQueryType.GetAllLibvirtSecretsByProviderId,
 parameters));
+    }
+
+    @Override
+    public Response add(OpenstackVolumeAuthenticationKey authenticationKey) {
+        validateParameters(authenticationKey, "uuid", "value", "usageType");
+        validateEnums(OpenstackVolumeAuthenticationKey.class, 
authenticationKey);
+        return performCreate(
+                VdcActionType.AddLibvirtSecret,
+                new 
LibvirtSecretParameters(map(addProvider(authenticationKey))),
+                new QueryIdResolver<Guid>(VdcQueryType.GetLibvirtSecretById, 
IdQueryParameters.class)
+        );
+    }
+
+    @Override
+    protected OpenstackVolumeAuthenticationKey 
doPopulate(OpenstackVolumeAuthenticationKey model, LibvirtSecret entity) {
+        return model;
+    }
+
+    protected OpenstackVolumeAuthenticationKeys 
mapCollection(List<LibvirtSecret> entities) {
+        OpenstackVolumeAuthenticationKeys collection = new 
OpenstackVolumeAuthenticationKeys();
+        for (LibvirtSecret libvirtSecret : entities) {
+            
collection.getOpenstackVolumeAuthenticationKeys().add(addLinks(populate(map(libvirtSecret),
 libvirtSecret)));
+        }
+        return collection;
+    }
+
+    @Override
+    protected OpenstackVolumeAuthenticationKey 
addParents(OpenstackVolumeAuthenticationKey authenticationKey) {
+        return super.addParents(addProvider(authenticationKey));
+    }
+
+    private OpenstackVolumeAuthenticationKey 
addProvider(OpenstackVolumeAuthenticationKey authenticationKey) {
+        OpenStackVolumeProvider provider = new OpenStackVolumeProvider();
+        provider.setId(providerId);
+        authenticationKey.setOpenstackVolumeProvider(provider);
+        return authenticationKey;
+    }
+
+    @Override
+    protected Response performRemove(String id) {
+        getEntity(id); //verifies that entity exists, returns 404 otherwise.
+        OpenStackVolumeAuthenticationKeyResource authenticationKeyResource = 
getOpenStackVolumeAuthenticationKey(id);
+        LibvirtSecret libvirtSecret = map(authenticationKeyResource.get(), 
null);
+        LibvirtSecretParameters parameters = new 
LibvirtSecretParameters(libvirtSecret);
+        return performAction(VdcActionType.RemoveLibvirtSecret, parameters);
+    }
+
+    @Override
+    @SingleEntityResource
+    public OpenStackVolumeAuthenticationKeyResource 
getOpenStackVolumeAuthenticationKey(String id) {
+        return inject(new 
BackendOpenStackVolumeAuthenticationKeyResource(providerId, id));
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProviderResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProviderResource.java
index 0900b04..89d2c0e 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProviderResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProviderResource.java
@@ -16,13 +16,14 @@
 
 package org.ovirt.engine.api.restapi.resource.openstack;
 
+import static 
org.ovirt.engine.api.restapi.resource.openstack.BackendOpenStackVolumeProvidersResource.SUB_COLLECTIONS;
+
 import org.ovirt.engine.api.model.OpenStackVolumeProvider;
+import 
org.ovirt.engine.api.resource.openstack.OpenStackVolumeAuthenticationKeysResource;
 import org.ovirt.engine.api.resource.openstack.OpenStackVolumeProviderResource;
 import org.ovirt.engine.api.resource.openstack.OpenStackVolumeTypesResource;
 import 
org.ovirt.engine.api.restapi.resource.AbstractBackendExternalProviderResource;
 import org.ovirt.engine.core.common.businessentities.Provider;
-
-import static 
org.ovirt.engine.api.restapi.resource.openstack.BackendOpenStackVolumeProvidersResource.SUB_COLLECTIONS;
 
 public class BackendOpenStackVolumeProviderResource
         extends 
AbstractBackendExternalProviderResource<OpenStackVolumeProvider>
@@ -41,6 +42,11 @@
     }
 
     @Override
+    public OpenStackVolumeAuthenticationKeysResource 
getOpenStackVolumeAuthenticationKeys() {
+        return inject(new 
BackendOpenStackVolumeAuthenticationKeysResource(id));
+    }
+
+    @Override
     protected OpenStackVolumeProvider doPopulate(OpenStackVolumeProvider 
model, Provider entity) {
         return parent.doPopulate(model, entity);
     }
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProvidersResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProvidersResource.java
index 0fa1b4b..0b343d7 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProvidersResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeProvidersResource.java
@@ -49,7 +49,7 @@
         implements OpenStackVolumeProvidersResource {
     static final String[] SUB_COLLECTIONS = {
         "volumetypes",
-        "certificates"
+        "authenticationkeys"
     };
 
     public BackendOpenStackVolumeProvidersResource() {
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/validation/OpenstackVolumeAuthenticationKeyValidator.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/validation/OpenstackVolumeAuthenticationKeyValidator.java
new file mode 100644
index 0000000..687cd66
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/validation/OpenstackVolumeAuthenticationKeyValidator.java
@@ -0,0 +1,17 @@
+package org.ovirt.engine.api.restapi.resource.validation;
+
+import org.ovirt.engine.api.common.util.EnumValidator;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKeyUsageType;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+
+@ValidatedClass(clazz = OpenstackVolumeAuthenticationKey.class)
+public class OpenstackVolumeAuthenticationKeyValidator implements 
Validator<OpenstackVolumeAuthenticationKey> {
+
+    @Override
+    public void validateEnums(OpenstackVolumeAuthenticationKey entity) {
+        if (entity != null) {
+            
EnumValidator.validateEnum(OpenstackVolumeAuthenticationKeyUsageType.class, 
entity.getUsageType(), true);
+        }
+    }
+
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResourceTest.java
new file mode 100644
index 0000000..cb278eb
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeyResourceTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.openstack;
+
+import static org.easymock.EasyMock.expect;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.junit.Test;
+import org.ovirt.engine.api.model.OpenStackVolumeProvider;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKeyUsageType;
+import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest;
+import org.ovirt.engine.api.restapi.utils.GuidUtils;
+import org.ovirt.engine.core.common.action.LibvirtSecretParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+import 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+
+public class BackendOpenStackVolumeAuthenticationKeyResourceTest
+        extends 
AbstractBackendSubResourceTest<OpenstackVolumeAuthenticationKey, LibvirtSecret, 
BackendOpenStackVolumeAuthenticationKeyResource> {
+    public BackendOpenStackVolumeAuthenticationKeyResourceTest() {
+        super(new 
BackendOpenStackVolumeAuthenticationKeyResource(GUIDS[0].toString(), 
GUIDS[1].toString()));
+    }
+
+    @Test
+    public void testBadId() throws Exception {
+        control.replay();
+        try {
+            new BackendOpenStackImageProviderResource("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);
+    }
+
+    @Override
+    protected LibvirtSecret getEntity(int index) {
+        LibvirtSecret libvirtSecret = control.createMock(LibvirtSecret.class);
+        expect(libvirtSecret.getId()).andReturn(GUIDS[index]).anyTimes();
+        
expect(libvirtSecret.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes();
+        expect(libvirtSecret.getProviderId()).andReturn(GUIDS[0]).anyTimes();
+        
expect(libvirtSecret.getUsageType()).andReturn(LibvirtSecretUsageType.CEPH).anyTimes();
+        return libvirtSecret;
+    }
+
+    private OpenstackVolumeAuthenticationKey getModel(int index) {
+        OpenstackVolumeAuthenticationKey model = new 
OpenstackVolumeAuthenticationKey();
+        model.setId(GUIDS[index].toString());
+        model.setDescription(DESCRIPTIONS[index]);
+        OpenStackVolumeProvider provider = new OpenStackVolumeProvider();
+        provider.setId(GUIDS[0].toString());
+        model.setOpenstackVolumeProvider(provider);
+        
model.setUsageType(OpenstackVolumeAuthenticationKeyUsageType.CEPH.name());
+        return model;
+    }
+
+    private void setUpGetEntityExpectations(boolean notFound) throws Exception 
{
+        setUpEntityQueryExpectations(
+                VdcQueryType.GetLibvirtSecretById,
+                IdQueryParameters.class,
+                new String[] { "Id" },
+                new Object[] { GUIDS[1] },
+                notFound ? null : getEntity(1));
+    }
+
+    @Override
+    protected void verifyModel(OpenstackVolumeAuthenticationKey model, int 
index) {
+        assertEquals(GUIDS[index], GuidUtils.asGuid(model.getId()));
+        assertEquals(DESCRIPTIONS[index], model.getDescription());
+        verifyLinks(model);
+    }
+
+    @Test
+    public void testUpdateNotFound() throws Exception {
+        setUriInfo(setUpBasicUriExpectations());
+        setUpGetEntityExpectations(1, true);
+        control.replay();
+        try {
+            resource.update(getModel(1));
+            fail("expected WebApplicationException");
+        } catch (WebApplicationException wae) {
+            verifyNotFoundException(wae);
+        }
+    }
+
+    @Test
+    public void testUpdate() throws Exception {
+        setUpGetEntityExpectations(2, false);
+        setUriInfo(setUpActionExpectations(
+                VdcActionType.UpdateLibvirtSecret,
+                LibvirtSecretParameters.class,
+                new String[] {},
+                new Object[] {},
+                true,
+                true));
+        verifyModel(resource.update(getModel(1)), 1);
+    }
+
+    protected void setUpGetEntityExpectations(int times, boolean notFound) 
throws Exception {
+        while (times-- > 0) {
+            setUpGetEntityExpectations(
+                    VdcQueryType.GetLibvirtSecretById,
+                    IdQueryParameters.class,
+                    new String[] { "Id" },
+                    new Object[] { GUIDS[1] },
+                    notFound ? null : getEntity(1));
+        }
+    }
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResourceTest.java
new file mode 100644
index 0000000..15799bd
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/openstack/BackendOpenStackVolumeAuthenticationKeysResourceTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.openstack;
+
+import static org.easymock.EasyMock.expect;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+import 
org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest;
+import org.ovirt.engine.api.restapi.utils.GuidUtils;
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+import 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+
+public class BackendOpenStackVolumeAuthenticationKeysResourceTest extends
+        
AbstractBackendCollectionResourceTest<OpenstackVolumeAuthenticationKey, 
LibvirtSecret, BackendOpenStackVolumeAuthenticationKeysResource> {
+    public BackendOpenStackVolumeAuthenticationKeysResourceTest() {
+        super(new 
BackendOpenStackVolumeAuthenticationKeysResource(GUIDS[0].toString()), null, 
"");
+    }
+
+    @Override
+    protected List<OpenstackVolumeAuthenticationKey> getCollection() {
+        return collection.list().getOpenstackVolumeAuthenticationKeys();
+    }
+
+    @Override
+    protected void setUpQueryExpectations(String query, Object failure) throws 
Exception {
+        setUpEntityQueryExpectations(
+                VdcQueryType.GetAllLibvirtSecretsByProviderId,
+                IdQueryParameters.class,
+                new String[] { "Id" },
+                new Object[] { GUIDS[0] }, getLibvirtSecrets(),
+                failure);
+        control.replay();
+    }
+
+    private List<LibvirtSecret> getLibvirtSecrets() {
+        List<LibvirtSecret> libvirtSecrets = new ArrayList<>();
+        for (int i = 0; i < NAMES.length; i++) {
+            libvirtSecrets.add(getEntity(i));
+        }
+        return libvirtSecrets;
+    }
+
+    @Override
+    protected LibvirtSecret getEntity(int index) {
+        LibvirtSecret libvirtSecret = control.createMock(LibvirtSecret.class);
+        expect(libvirtSecret.getId()).andReturn(GUIDS[index]).anyTimes();
+        
expect(libvirtSecret.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes();
+        expect(libvirtSecret.getProviderId()).andReturn(GUIDS[0]).anyTimes();
+        
expect(libvirtSecret.getUsageType()).andReturn(LibvirtSecretUsageType.CEPH).anyTimes();
+        return libvirtSecret;
+    }
+
+    @Override
+    protected void verifyModel(OpenstackVolumeAuthenticationKey model, int 
index) {
+        assertEquals(GUIDS[index], GuidUtils.asGuid(model.getId()));
+        assertEquals(DESCRIPTIONS[index], model.getDescription());
+        verifyLinks(model);
+    }
+}
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackVolumeAuthenticationKeyMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackVolumeAuthenticationKeyMapper.java
new file mode 100644
index 0000000..20f8c3c
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/openstack/OpenStackVolumeAuthenticationKeyMapper.java
@@ -0,0 +1,103 @@
+/*
+ * 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.openstack;
+
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKeyUsageType;
+import org.ovirt.engine.api.model.OpenStackVolumeProvider;
+import org.ovirt.engine.api.model.OpenstackVolumeAuthenticationKey;
+import org.ovirt.engine.api.restapi.types.DateMapper;
+import org.ovirt.engine.api.restapi.types.Mapping;
+import org.ovirt.engine.api.restapi.utils.GuidUtils;
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+
+public class OpenStackVolumeAuthenticationKeyMapper {
+    @Mapping(from = LibvirtSecret.class, to = 
OpenstackVolumeAuthenticationKey.class)
+    public static OpenstackVolumeAuthenticationKey map(LibvirtSecret entity, 
OpenstackVolumeAuthenticationKey template) {
+        OpenstackVolumeAuthenticationKey model = template != null ? template : 
new OpenstackVolumeAuthenticationKey();
+        if (entity.getId() != null) {
+            model.setId(entity.getId().toString());
+            model.setUuid(entity.getId().toString());
+        }
+        if (entity.getDescription() != null) {
+            model.setDescription(entity.getDescription());
+        }
+        if (entity.getCreationDate() != null) {
+            model.setCreationDate(DateMapper.map(entity.getCreationDate(), 
null));
+        }
+        if (entity.getUsageType() != null) {
+            model.setUsageType(map(entity.getUsageType(), null));
+        }
+        if (entity.getProviderId() != null) {
+            OpenStackVolumeProvider provider = new OpenStackVolumeProvider();
+            provider.setId(entity.getProviderId().toString());
+            model.setOpenstackVolumeProvider(provider);
+        }
+        return model;
+    }
+
+    @Mapping(from = OpenstackVolumeAuthenticationKey.class, to = 
LibvirtSecret.class)
+    public static LibvirtSecret map(OpenstackVolumeAuthenticationKey model, 
LibvirtSecret template) {
+        LibvirtSecret entity = template != null ? template : new 
LibvirtSecret();
+        if (model.isSetId()) {
+            entity.setId(GuidUtils.asGuid(model.getId()));
+        }
+        if (model.isSetUuid()) {
+            entity.setId(GuidUtils.asGuid(model.getUuid()));
+        }
+        if (model.isSetDescription()) {
+            entity.setDescription(model.getDescription());
+        }
+        if (model.isSetValue()) {
+            entity.setValue(model.getValue());
+        }
+        if (model.isSetUsageType()) {
+            OpenstackVolumeAuthenticationKeyUsageType usageType = 
OpenstackVolumeAuthenticationKeyUsageType.fromValue(model.getUsageType());
+            if (usageType != null) {
+                entity.setUsageType(map(usageType, null));
+            }
+        }
+        if (model.isSetOpenstackVolumeProvider()) {
+            
entity.setProviderId(GuidUtils.asGuid(model.getOpenstackVolumeProvider().getId()));
+        }
+        return entity;
+    }
+
+    @Mapping(from = 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType.class,
+            to = String.class)
+    public static String 
map(org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType
 usageType,
+            String template) {
+        switch (usageType) {
+        case CEPH:
+            return OpenstackVolumeAuthenticationKeyUsageType.CEPH.value();
+        default:
+            return null;
+        }
+    }
+
+    @Mapping(from = OpenstackVolumeAuthenticationKeyUsageType.class,
+            to = 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType.class)
+    public static 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType 
map(
+            OpenstackVolumeAuthenticationKeyUsageType usageType,
+            
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType 
outgoing) {
+        switch (usageType) {
+        case CEPH:
+            return 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType.CEPH;
+        default:
+            return null;
+        }
+    }
+}


-- 
To view, visit https://gerrit.ovirt.org/41969
To unsubscribe, visit https://gerrit.ovirt.org/settings

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

Reply via email to