From e153f0adfbed711ce1e215748594a4d04fd1edaf Mon Sep 17 00:00:00 2001 From: "Smokowski, Steve (ss835w)" Date: Thu, 2 May 2019 09:42:55 -0400 Subject: Enhance Openstack Client Update Openstack Client to support Cinder, and drop null query params Issue-ID: SO-1844 Change-Id: If58717656e0468ec0ce5d53055c381fe7d1c03f5 Signed-off-by: Smokowski, Steve (ss835w) --- cinder-client/pom.xml | 26 +++ .../java/com/woorea/openstack/cinder/Cinder.java | 65 ++++++++ .../woorea/openstack/cinder/LimitsExtension.java | 42 +++++ .../openstack/cinder/SchedulerStatsExtension.java | 44 +++++ .../openstack/cinder/SnapshotsExtension.java | 125 +++++++++++++++ .../openstack/cinder/VolumeTypesExtension.java | 84 ++++++++++ .../woorea/openstack/cinder/VolumesExtension.java | 178 +++++++++++++++++++++ 7 files changed, 564 insertions(+) create mode 100755 cinder-client/pom.xml create mode 100755 cinder-client/src/main/java/com/woorea/openstack/cinder/Cinder.java create mode 100755 cinder-client/src/main/java/com/woorea/openstack/cinder/LimitsExtension.java create mode 100755 cinder-client/src/main/java/com/woorea/openstack/cinder/SchedulerStatsExtension.java create mode 100755 cinder-client/src/main/java/com/woorea/openstack/cinder/SnapshotsExtension.java create mode 100755 cinder-client/src/main/java/com/woorea/openstack/cinder/VolumeTypesExtension.java create mode 100755 cinder-client/src/main/java/com/woorea/openstack/cinder/VolumesExtension.java (limited to 'cinder-client') diff --git a/cinder-client/pom.xml b/cinder-client/pom.xml new file mode 100755 index 0000000..47978ac --- /dev/null +++ b/cinder-client/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + + org.onap.so.libs + openstack-java-sdk + 1.4.0-SNAPSHOT + + cinder-client + OpenStack Cinder Client + OpenStack Cinder Client + + + org.onap.so.libs.openstack-java-sdk + openstack-client + ${project.version} + + + + org.onap.so.libs.openstack-java-sdk + cinder-model + ${project.version} + + + org.onap.so.libs.openstack-java-sdk + \ No newline at end of file diff --git a/cinder-client/src/main/java/com/woorea/openstack/cinder/Cinder.java b/cinder-client/src/main/java/com/woorea/openstack/cinder/Cinder.java new file mode 100755 index 0000000..ca65d3f --- /dev/null +++ b/cinder-client/src/main/java/com/woorea/openstack/cinder/Cinder.java @@ -0,0 +1,65 @@ +/* ============LICENSE_START======================================================= + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.cinder; + +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackClientConnector; + +public class Cinder extends OpenStackClient { + + private final VolumesExtension VOLUMES; + + private final SnapshotsExtension SNAPSHOTS; + + private final VolumeTypesExtension VOLUME_TYPES; + + private final LimitsExtension LIMITS; + + private final SchedulerStatsExtension SCHEDULER_STATS; + + public Cinder(String endpoint, OpenStackClientConnector connector) { + super(endpoint, connector); + VOLUMES = new VolumesExtension(this); + SNAPSHOTS = new SnapshotsExtension(this); + VOLUME_TYPES = new VolumeTypesExtension(this); + LIMITS = new LimitsExtension(this); + SCHEDULER_STATS = new SchedulerStatsExtension(this); + } + + public Cinder(String endpoint) { + this(endpoint, null); + } + + public final VolumesExtension volumes() { + return VOLUMES; + } + + public final SnapshotsExtension snapshots() { + return SNAPSHOTS; + } + + public final VolumeTypesExtension volumeTypes() { + return VOLUME_TYPES; + } + + public final LimitsExtension limits() { + return LIMITS; + } + + public final SchedulerStatsExtension schedulerStats() { + return SCHEDULER_STATS; + } +} diff --git a/cinder-client/src/main/java/com/woorea/openstack/cinder/LimitsExtension.java b/cinder-client/src/main/java/com/woorea/openstack/cinder/LimitsExtension.java new file mode 100755 index 0000000..32c05d7 --- /dev/null +++ b/cinder-client/src/main/java/com/woorea/openstack/cinder/LimitsExtension.java @@ -0,0 +1,42 @@ +/* ============LICENSE_START======================================================= + * 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. + * ============LICENSE_END========================================================= + */ +package com.woorea.openstack.cinder; + +import com.woorea.openstack.base.client.HttpMethod; +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.cinder.model.Limits; + +public class LimitsExtension { + + private final OpenStackClient CLIENT; + + public LimitsExtension(OpenStackClient client) { + CLIENT = client; + } + + public List list() { + return new List(); + } + + public class List extends OpenStackRequest { + + public List() { + super(CLIENT, HttpMethod.GET, "/limits", null, Limits.class); + } + + } + +} diff --git a/cinder-client/src/main/java/com/woorea/openstack/cinder/SchedulerStatsExtension.java b/cinder-client/src/main/java/com/woorea/openstack/cinder/SchedulerStatsExtension.java new file mode 100755 index 0000000..09ad3ac --- /dev/null +++ b/cinder-client/src/main/java/com/woorea/openstack/cinder/SchedulerStatsExtension.java @@ -0,0 +1,44 @@ +/* ============LICENSE_START======================================================= + * 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. + * ============LICENSE_END========================================================= + */ +package com.woorea.openstack.cinder; + +import com.woorea.openstack.base.client.HttpMethod; +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.cinder.model.Pools; + +/** + * Cinder Scheduler Stats Management + */ +public class SchedulerStatsExtension { + + private final OpenStackClient CLIENT; + + public SchedulerStatsExtension(OpenStackClient client) { + this.CLIENT = client; + } + + public List list(boolean detail) { + return new List(detail); + } + + public class List extends OpenStackRequest { + + public List(boolean detail) { + super(CLIENT, HttpMethod.GET, (new StringBuilder("/scheduler-stats/get_pools")).append(detail ? "?detail=True":""), null, Pools.class); + } + } + +} diff --git a/cinder-client/src/main/java/com/woorea/openstack/cinder/SnapshotsExtension.java b/cinder-client/src/main/java/com/woorea/openstack/cinder/SnapshotsExtension.java new file mode 100755 index 0000000..d01bdc9 --- /dev/null +++ b/cinder-client/src/main/java/com/woorea/openstack/cinder/SnapshotsExtension.java @@ -0,0 +1,125 @@ +/* ============LICENSE_START======================================================= + * 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. + * ============LICENSE_END========================================================= + */ +package com.woorea.openstack.cinder; + +import com.woorea.openstack.base.client.Entity; +import com.woorea.openstack.base.client.HttpMethod; +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.cinder.model.Metadata; +import com.woorea.openstack.cinder.model.Snapshot; +import com.woorea.openstack.cinder.model.SnapshotForCreate; +import com.woorea.openstack.cinder.model.SnapshotForUpdate; +import com.woorea.openstack.cinder.model.Snapshots; + +public class SnapshotsExtension { + + private final OpenStackClient CLIENT; + + public SnapshotsExtension(OpenStackClient client) { + CLIENT = client; + } + + public List list(boolean detail) { + return new List(detail); + } + + public Create create(SnapshotForCreate snapshotForCreate) { + return new Create(snapshotForCreate); + } + + public Show show(String id) { + return new Show(id); + } + + public ShowMetadata showMetadata(String snapshotId) { + return new ShowMetadata(snapshotId); + } + + public UpdateMetadata updateMetadata(String snapshotId, Metadata metadata) { + return new UpdateMetadata(snapshotId, metadata); + } + + public Delete delete(String id) { + return new Delete(id); + } + + public Update update(String id, SnapshotForUpdate snapshot) { + return new Update(id, snapshot); + } + + public class List extends OpenStackRequest { + + public List(boolean detail) { + super(CLIENT, HttpMethod.GET, detail ? "/snapshots/detail" : "/snapshots", null, Snapshots.class); + } + + } + + public class Create extends OpenStackRequest { + + public Create(SnapshotForCreate snapshotForCreate) { + super(CLIENT, HttpMethod.POST, "/snapshots", Entity.json(snapshotForCreate), Snapshot.class); + } + + } + + public class Show extends OpenStackRequest { + + public Show(String id) { + super(CLIENT, HttpMethod.GET, new StringBuilder("/snapshots/").append(id).toString(), null, Snapshot.class); + } + + } + + public class Delete extends OpenStackRequest { + + public Delete(String id) { + super(CLIENT, HttpMethod.DELETE, new StringBuilder("/snapshots/").append(id).toString(), null, Void.class); + } + + } + + public class Update extends OpenStackRequest { + + public Update(String id, SnapshotForUpdate snapshot) { + super(CLIENT, HttpMethod.PUT, new StringBuilder("/snapshots/").append(id).toString(), + Entity.json(snapshot), Void.class); + } + + } + + public class ShowMetadata extends OpenStackRequest { + + public ShowMetadata(String id) { + super(CLIENT, + HttpMethod.GET, + new StringBuilder("/snapshots/").append(id).append("/metadata").toString(), + null, + Metadata.class); + } + + } + + public class UpdateMetadata extends OpenStackRequest { + + public UpdateMetadata(String snapshotId, Metadata metadata) { + super(CLIENT, HttpMethod.PUT, new StringBuilder("/snapshots/").append(snapshotId) + .append("/metadata") + .toString(), Entity.json(metadata), Void.class); + } + + } +} diff --git a/cinder-client/src/main/java/com/woorea/openstack/cinder/VolumeTypesExtension.java b/cinder-client/src/main/java/com/woorea/openstack/cinder/VolumeTypesExtension.java new file mode 100755 index 0000000..ded5768 --- /dev/null +++ b/cinder-client/src/main/java/com/woorea/openstack/cinder/VolumeTypesExtension.java @@ -0,0 +1,84 @@ +/* ============LICENSE_START======================================================= + * 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. + * ============LICENSE_END========================================================= + */ +package com.woorea.openstack.cinder; + +import com.woorea.openstack.base.client.Entity; +import com.woorea.openstack.base.client.HttpMethod; +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.cinder.model.VolumeType; +import com.woorea.openstack.cinder.model.VolumeTypeForCreate; +import com.woorea.openstack.cinder.model.VolumeTypes; + +public class VolumeTypesExtension { + + private final OpenStackClient CLIENT; + + public VolumeTypesExtension(OpenStackClient client) { + CLIENT = client; + } + + public List list() { + return new List(); + } + + public Create create(VolumeTypeForCreate volumeTypeForCreate) { + return new Create(volumeTypeForCreate); + } + + public Show show(String id) { + return new Show(id); + } + + public Delete delete(String id) { + return new Delete(id); + } + + public class List extends OpenStackRequest { + + public List() { + super(CLIENT, HttpMethod.GET, "/types", null, VolumeTypes.class); + } + + } + + public class Create extends OpenStackRequest { + + private VolumeTypeForCreate volumeTypeForCreate; + + public Create(VolumeTypeForCreate volumeTypeForCreate) { + super(CLIENT, HttpMethod.POST, "/types", Entity.json(volumeTypeForCreate), VolumeType.class); + this.volumeTypeForCreate = volumeTypeForCreate; + } + + } + + public class Show extends OpenStackRequest { + + public Show(String id) { + super(CLIENT, HttpMethod.GET, new StringBuilder("/types/").append(id).toString(), null, VolumeType.class); + } + + } + + public class Delete extends OpenStackRequest { + + public Delete(String id) { + super(CLIENT, HttpMethod.DELETE, new StringBuilder("/types/").append(id).toString(), null, Void.class); + } + + } + +} diff --git a/cinder-client/src/main/java/com/woorea/openstack/cinder/VolumesExtension.java b/cinder-client/src/main/java/com/woorea/openstack/cinder/VolumesExtension.java new file mode 100755 index 0000000..3e6bf97 --- /dev/null +++ b/cinder-client/src/main/java/com/woorea/openstack/cinder/VolumesExtension.java @@ -0,0 +1,178 @@ +/* ============LICENSE_START======================================================= + * 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. + * ============LICENSE_END========================================================= + */ +package com.woorea.openstack.cinder; + +import com.woorea.openstack.base.client.Entity; +import com.woorea.openstack.base.client.HttpMethod; +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.cinder.model.ConnectionForInitialize; +import com.woorea.openstack.cinder.model.ConnectionForTerminate; +import com.woorea.openstack.cinder.model.ConnectionInfo; +import com.woorea.openstack.cinder.model.Metadata; +import com.woorea.openstack.cinder.model.Volume; +import com.woorea.openstack.cinder.model.VolumeForCreate; +import com.woorea.openstack.cinder.model.VolumeForExtend; +import com.woorea.openstack.cinder.model.VolumeForImageCreate; +import com.woorea.openstack.cinder.model.VolumeForUpdate; +import com.woorea.openstack.cinder.model.Volumes; + +public class VolumesExtension { + + private final OpenStackClient CLIENT; + + public VolumesExtension(OpenStackClient client) { + CLIENT = client; + } + + public List list(boolean detail) { + return new List(detail); + } + + public Create create(VolumeForCreate volume) { + return new Create(volume); + } + + public UploadToImage uploadToImage(VolumeForImageCreate volumeForImage) { + return new UploadToImage(volumeForImage); + } + + public Show show(String id) { + return new Show(id); + } + + public ShowMetadata showMetadata(String id) { + return new ShowMetadata(id); + } + + public Delete delete(String id) { + return new Delete(id); + } + + public Update update(String id, VolumeForUpdate volume) { + return new Update(id, volume); + } + + public Extend extend(String id, int newSize) { + VolumeForExtend volume = new VolumeForExtend(); + volume.setSize(newSize); + return new Extend(id, volume); + } + + public InitializeConnection initializeConnection(String id, ConnectionForInitialize connectionForInitialize) { + return new InitializeConnection(id, connectionForInitialize); + } + + public TerminateConnection terminateConnection(String id, ConnectionForTerminate connectionForTerminate) { + return new TerminateConnection(id, connectionForTerminate); + } + + public class List extends OpenStackRequest { + + public List(boolean detail) { + super(CLIENT, HttpMethod.GET, detail ? "/volumes/detail" + : "/volumes", null, Volumes.class); + } + + } + + public class Create extends OpenStackRequest { + + public Create(VolumeForCreate volume) { + super(CLIENT, HttpMethod.POST, "/volumes", Entity.json(volume), + Volume.class); + } + + } + + // Upload volume to image service as image + + public class UploadToImage extends OpenStackRequest { + + public UploadToImage(VolumeForImageCreate volumeForImageCreate) { + super(CLIENT, HttpMethod.POST, new StringBuilder("/volumes/") + .append(volumeForImageCreate.getVolumeId() + "/action").toString(), + Entity.json(volumeForImageCreate), Void.class); + } + + } + + public class Show extends OpenStackRequest { + + public Show(String id) { + super(CLIENT, HttpMethod.GET, new StringBuilder("/volumes/") + .append(id).toString(), null, Volume.class); + } + + } + + public class ShowMetadata extends OpenStackRequest { + + public ShowMetadata(String id) { + super(CLIENT, HttpMethod.GET, new StringBuilder("/volumes/") + .append(id).append("/metadata").toString(), null, + Metadata.class); + } + + } + + public class Delete extends OpenStackRequest { + + public Delete(String id) { + super(CLIENT, HttpMethod.DELETE, new StringBuilder("/volumes/") + .append(id).toString(), null, Void.class); + } + + } + + public class Update extends OpenStackRequest { + + public Update(String id, VolumeForUpdate volume) { + super(CLIENT, HttpMethod.PUT, new StringBuilder("/volumes/").append(id).toString(), + Entity.json(volume), Void.class); + } + + } + + public class Extend extends OpenStackRequest { + + public Extend(String id, VolumeForExtend volume) { + super(CLIENT, HttpMethod.POST, new StringBuilder("/volumes/").append(id).append("/action").toString(), + Entity.json(volume), Void.class); + } + + } + + public class InitializeConnection extends OpenStackRequest { + + public InitializeConnection(String id, ConnectionForInitialize connectionForInitialize) { + super(CLIENT, HttpMethod.POST, new StringBuilder("/volumes/") + .append(id).append("/action").toString(), + Entity.json(connectionForInitialize), ConnectionInfo.class); + } + + } + + public class TerminateConnection extends OpenStackRequest { + + public TerminateConnection(String id, ConnectionForTerminate connectionForTerminate) { + super(CLIENT, HttpMethod.POST, new StringBuilder("/volumes/") + .append(id).append("/action").toString(), + Entity.json(connectionForTerminate), Void.class); + } + + } + +} -- cgit 1.2.3-korg