From 0a14171a5271b2f9431cf5107ba5bf2567f0b082 Mon Sep 17 00:00:00 2001 From: andreisavu Date: Mon, 5 Dec 2011 21:13:52 +0200 Subject: [PATCH] Implement the Cloudstack global admin service offerings API --- .../CloudStackGlobalAsyncClient.java | 8 + .../cloudstack/CloudStackGlobalClient.java | 8 + .../config/CloudStackRestClientModule.java | 1 + .../cloudstack/domain/SystemVmType.java | 49 ++++ .../features/GlobalOfferingAsyncClient.java | 88 ++++++++ .../features/GlobalOfferingClient.java | 79 +++++++ .../options/CreateServiceOfferingOptions.java | 211 ++++++++++++++++++ .../options/UpdateServiceOfferingOptions.java | 107 +++++++++ .../GlobalOfferingClientLiveTest.java | 78 +++++++ .../CreateServiceOfferingOptionsTest.java | 126 +++++++++++ .../UpdateServiceOfferingOptionsTest.java | 67 ++++++ 11 files changed, 822 insertions(+) create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SystemVmType.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptions.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptionsTest.java create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptionsTest.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java index d3ae5350dc..19192c82f7 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalAsyncClient.java @@ -20,6 +20,7 @@ package org.jclouds.cloudstack; import org.jclouds.cloudstack.features.GlobalAccountAsyncClient; import org.jclouds.cloudstack.features.GlobalAlertAsyncClient; +import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient; import org.jclouds.rest.annotations.Delegate; /** @@ -47,4 +48,11 @@ public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient @Delegate GlobalAlertAsyncClient getAlertClient(); + /** + * Provides asynchronous access to Offerings + */ + @Delegate + @Override + GlobalOfferingAsyncClient getOfferingClient(); + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java index 6d115b557b..26f64a9c38 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackGlobalClient.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.cloudstack.features.GlobalAccountClient; import org.jclouds.cloudstack.features.GlobalAlertClient; +import org.jclouds.cloudstack.features.GlobalOfferingClient; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; @@ -51,4 +52,11 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient { @Delegate GlobalAlertClient getAlertClient(); + /** + * Provides synchronous access to Offerings + */ + @Delegate + @Override + GlobalOfferingClient getOfferingClient(); + } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index d3e52d42cc..238ae4c2f1 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -130,6 +130,7 @@ public class CloudStackRestClientModule extends RestClientModule + * + * @see GlobalOfferingClient + * @see + * @author Andrei Savu + */ +@RequestFilters(QuerySigner.class) +@QueryParams(keys = "response", values = "json") +public interface GlobalOfferingAsyncClient extends OfferingAsyncClient { + + /** + * @see GlobalOfferingClient#createServiceOffering + */ + @GET + @QueryParams(keys = "command", values = "createServiceOffering") + @SelectJson("serviceoffering") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture createServiceOffering(@QueryParam("name") String name, @QueryParam("displaytext") String displayText, + @QueryParam("cpunumber") int cpuNumber, @QueryParam("cpuspeed") int cpuSpeedInMHz, @QueryParam("memory") int memoryInMB, CreateServiceOfferingOptions... options); + + + /** + * @see GlobalOfferingClient#updateServiceOffering + */ + @GET + @QueryParams(keys = "command", values = "updateServiceOffering") + @SelectJson("serviceoffering") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture updateServiceOffering(@QueryParam("id") long id, UpdateServiceOfferingOptions... options); + + /** + * @see GlobalOfferingClient#deleteServiceOffering + */ + @GET + @QueryParams(keys = "command", values = "deleteServiceOffering") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture deleteServiceOffering(@QueryParam("id") long id); + +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java new file mode 100644 index 0000000000..3917268733 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingClient.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.jclouds.cloudstack.features; + +import org.jclouds.cloudstack.domain.ServiceOffering; +import org.jclouds.cloudstack.options.CreateServiceOfferingOptions; +import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; +import org.jclouds.concurrent.Timeout; + +import java.util.concurrent.TimeUnit; + +/** + * Provides synchronous access to CloudStack zone features. + *

+ * + * @see GlobalOfferingAsyncClient + * @see + * @author Andrei Savu + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface GlobalOfferingClient extends OfferingClient { + + /** + * Create a new service offering + * + * @param name + * name of the service offering + * @param displayText + * display name + * @param cpuNumber + * number of CPUs + * @param cpuSpeedInMHz + * CPU speed in MHz + * @param memoryInMB + * the total memory of the service offering in MB + * @param options + * optional arguments + * @return + * service offering instance + */ + ServiceOffering createServiceOffering(String name, String displayText, int cpuNumber, + int cpuSpeedInMHz, int memoryInMB, CreateServiceOfferingOptions... options); + + /** + * Update an existing service offering + * + * @param id + * service offering ID + * @param options + * optional arguments + * @return + * service offering instance + */ + ServiceOffering updateServiceOffering(long id, UpdateServiceOfferingOptions... options); + + /** + * Delete service offering + * + * @param id + * the ID of the service offering + */ + Void deleteServiceOffering(long id); +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptions.java new file mode 100644 index 0000000000..c724c30331 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptions.java @@ -0,0 +1,211 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.StorageType; +import org.jclouds.cloudstack.domain.SystemVmType; + +import java.util.Set; + +/** + * Options to control how service offerings are created + * + * @see + * @author Andrei Savu + */ +public class CreateServiceOfferingOptions extends AccountInDomainOptions { + + public static final CreateServiceOfferingOptions NONE = new CreateServiceOfferingOptions(); + + /** + * @param hostTags + * the host tag for this service offering + */ + public CreateServiceOfferingOptions hostTags(Set hostTags) { + this.queryParameters.replaceValues("hosttags", ImmutableSet.copyOf(hostTags)); + return this; + } + + /** + * @param isSystem + * is this a system vm offering + */ + public CreateServiceOfferingOptions isSystem(boolean isSystem) { + this.queryParameters.replaceValues("issystem", ImmutableSet.of(isSystem + "")); + return this; + } + + /** + * @param limitCpuUse + * restrict the CPU usage to committed service offering + */ + public CreateServiceOfferingOptions limitCpuUse(boolean limitCpuUse) { + this.queryParameters.replaceValues("limitcpuuse", ImmutableSet.of(limitCpuUse + "")); + return this; + } + + /** + * @param networkRateInMb + * data transfer rate in megabits per second allowed. Supported only + * for non-System offering and system offerings having "domainrouter" + * systemvmtype + */ + public CreateServiceOfferingOptions networkRateInMb(int networkRateInMb) { + this.queryParameters.replaceValues("networkrate", ImmutableSet.of(networkRateInMb + "")); + return this; + } + + /** + * @param highlyAvailable + * the HA for the service offering + */ + public CreateServiceOfferingOptions highlyAvailable(boolean highlyAvailable) { + this.queryParameters.replaceValues("offerha", ImmutableSet.of(highlyAvailable + "")); + return this; + } + + /** + * @param storageType + * the storage type of the service offering + */ + public CreateServiceOfferingOptions storageType(StorageType storageType) { + this.queryParameters.replaceValues("storagetype", ImmutableSet.of(storageType.toString())); + return this; + } + + /** + * @param systemVmType + * the system VM type. Possible types are "domainrouter", "consoleproxy" and "secondarystoragevm" + */ + public CreateServiceOfferingOptions systemVmType(SystemVmType systemVmType) { + this.queryParameters.replaceValues("systemvmtype", ImmutableSet.of(systemVmType.toString())); + return this; + } + + /** + * @param tags + * the tags for this service offering + */ + public CreateServiceOfferingOptions tags(Set tags) { + this.queryParameters.replaceValues("tags", ImmutableSet.copyOf(tags)); + return this; + } + + public static class Builder { + + /** + * @see CreateServiceOfferingOptions#hostTags + */ + public static CreateServiceOfferingOptions hostTags(Set hostTags) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.hostTags(hostTags); + } + + /** + * @see CreateServiceOfferingOptions#isSystem + */ + public static CreateServiceOfferingOptions isSystem(boolean isSystem) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.isSystem(isSystem); + } + + /** + * @see CreateServiceOfferingOptions#limitCpuUse + */ + public static CreateServiceOfferingOptions limitCpuUse(boolean limitCpuUse) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.limitCpuUse(limitCpuUse); + } + + /** + * @see CreateServiceOfferingOptions#networkRateInMb + */ + public static CreateServiceOfferingOptions networkRateInMb(int networkRate) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.networkRateInMb(networkRate); + } + + /** + * @see CreateServiceOfferingOptions#highlyAvailable + */ + public static CreateServiceOfferingOptions highlyAvailable(boolean highlyAvailable) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.highlyAvailable(highlyAvailable); + } + + /** + * @see CreateServiceOfferingOptions#storageType + */ + public static CreateServiceOfferingOptions storageType(StorageType storageType) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.storageType(storageType); + } + + /** + * @see CreateServiceOfferingOptions#systemVmType + */ + public static CreateServiceOfferingOptions systemVmType(SystemVmType systemVmType) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.systemVmType(systemVmType); + } + + /** + * @see CreateServiceOfferingOptions#tags + */ + public static CreateServiceOfferingOptions tags(Set tags) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.tags(tags); + } + + /** + * @see CreateServiceOfferingOptions#accountInDomain + */ + public static CreateServiceOfferingOptions accountInDomain(String account, long domain) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.accountInDomain(account, domain); + } + + /** + * @see CreateServiceOfferingOptions#domainId + */ + public static CreateServiceOfferingOptions domainId(long domainId) { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions(); + return options.domainId(domainId); + } + } + + /** + * {@inheritDoc} + */ + @Override + public CreateServiceOfferingOptions accountInDomain(String account, long domain) { + return CreateServiceOfferingOptions.class.cast(super.accountInDomain(account, domain)); + } + + /** + * {@inheritDoc} + */ + @Override + public CreateServiceOfferingOptions domainId(long domainId) { + return CreateServiceOfferingOptions.class.cast(super.domainId(domainId)); + } +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java new file mode 100644 index 0000000000..fb09236a98 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java @@ -0,0 +1,107 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.StorageType; +import org.jclouds.cloudstack.domain.SystemVmType; + +import java.util.Set; + +/** + * Options to control how service offerings are created + * + * @see + * @author Andrei Savu + */ +public class UpdateServiceOfferingOptions extends AccountInDomainOptions { + + public static final UpdateServiceOfferingOptions NONE = new UpdateServiceOfferingOptions(); + + /** + * @param name + * service offering name + */ + public UpdateServiceOfferingOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + + /** + * @param displayText + * service offering display text + */ + public UpdateServiceOfferingOptions displayText(String displayText) { + this.queryParameters.replaceValues("displaytext", ImmutableSet.of(displayText)); + return this; + } + + public static class Builder { + + /** + * @see UpdateServiceOfferingOptions#name + */ + public static UpdateServiceOfferingOptions name(String name) { + UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions(); + return options.name(name); + } + + /** + * @see UpdateServiceOfferingOptions#displayText + */ + public static UpdateServiceOfferingOptions displayText(String displayText) { + UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions(); + return options.displayText(displayText); + } + + /** + * @see UpdateServiceOfferingOptions#accountInDomain + */ + public static UpdateServiceOfferingOptions accountInDomain(String account, long domain) { + UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions(); + return options.accountInDomain(account, domain); + } + + /** + * @see UpdateServiceOfferingOptions#domainId + */ + public static UpdateServiceOfferingOptions domainId(long domainId) { + UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions(); + return options.domainId(domainId); + } + } + + /** + * {@inheritDoc} + */ + @Override + public UpdateServiceOfferingOptions accountInDomain(String account, long domain) { + return UpdateServiceOfferingOptions.class.cast(super.accountInDomain(account, domain)); + } + + /** + * {@inheritDoc} + */ + @Override + public UpdateServiceOfferingOptions domainId(long domainId) { + return UpdateServiceOfferingOptions.class.cast(super.domainId(domainId)); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java new file mode 100644 index 0000000000..4bcbf62ea7 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingClientLiveTest.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.jclouds.cloudstack.features; + +import org.jclouds.cloudstack.domain.ServiceOffering; +import org.jclouds.cloudstack.domain.StorageType; +import org.jclouds.logging.Logger; +import org.testng.annotations.Test; + +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable; +import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.name; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Tests behavior of {@code GlobalOfferingClient} + * + * @author Andrei Savu + */ +@Test(groups = "live", singleThreaded = true, testName = "GlobalOfferingClientLiveTest") +public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest { + + @Test(groups = "live", enabled = true) + public void testCreateServiceOffering() throws Exception { + assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials"); + + String name = prefix + "-test-create-service-offering"; + String displayText = name + "-display"; + ServiceOffering offering = null; + try { + offering = globalAdminClient.getOfferingClient(). + createServiceOffering(name, displayText, 2, 1024, 2048, highlyAvailable(true).storageType(StorageType.LOCAL)); + Logger.CONSOLE.info("Created Service Offering: " + offering); + + assertEquals(offering.getName(), name); + assertEquals(offering.getDisplayText(), displayText); + checkServiceOffering(offering); + + offering = globalAdminClient.getOfferingClient() + .updateServiceOffering(offering.getId(), name(name + "-2").displayText(displayText + "-2")); + + assertEquals(offering.getName(), name + "-2"); + assertEquals(offering.getDisplayText(), displayText + "-2"); + checkServiceOffering(offering); + + } finally { + if (offering != null) { + globalAdminClient.getOfferingClient().deleteServiceOffering(offering.getId()); + } + } + } + + private void checkServiceOffering(ServiceOffering offering) { + assertTrue(offering.getId() > 0); + assertEquals(offering.getCpuNumber(), 2); + assertEquals(offering.getCpuSpeed(), 1024); + assertEquals(offering.getMemory(), 2048); + assertTrue(offering.supportsHA()); + assertEquals(offering.getStorageType(), StorageType.LOCAL); + } + +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptionsTest.java new file mode 100644 index 0000000000..351d9bae29 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/CreateServiceOfferingOptionsTest.java @@ -0,0 +1,126 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.StorageType; +import org.jclouds.cloudstack.domain.SystemVmType; +import org.testng.annotations.Test; + +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.hostTags; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.isSystem; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.limitCpuUse; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.networkRateInMb; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.storageType; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.systemVmType; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.tags; +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@code CreateServiceOfferingOptions} + * + * @author Andrei Savu + */ +@Test(groups = "unit") +public class CreateServiceOfferingOptionsTest { + + public void testHostTags() { + CreateServiceOfferingOptions options = + new CreateServiceOfferingOptions().hostTags(ImmutableSet.of("tag1", "tag2")); + assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("hosttags")); + } + + public void testHostTagsStatic() { + CreateServiceOfferingOptions options = hostTags(ImmutableSet.of("tag1", "tag2")); + assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("hosttags")); + } + + public void testIsSystem() { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().isSystem(true); + assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("issystem")); + } + + public void testIsSystemStatic() { + CreateServiceOfferingOptions options = isSystem(true); + assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("issystem")); + } + + public void testLimitCpuUse() { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().limitCpuUse(true); + assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("limitcpuuse")); + } + + public void testLimitCpuUseStatic() { + CreateServiceOfferingOptions options = limitCpuUse(true); + assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("limitcpuuse")); + } + + public void testNetworkRate() { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().networkRateInMb(200); + assertEquals(ImmutableSet.of("200"), options.buildQueryParameters().get("networkrate")); + } + + public void testNetworkRateStatic() { + CreateServiceOfferingOptions options = networkRateInMb(200); + assertEquals(ImmutableSet.of("200"), options.buildQueryParameters().get("networkrate")); + } + + public void testHighlyAvailable() { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().highlyAvailable(true); + assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("offerha")); + } + + public void testHighlyAvailableStatic() { + CreateServiceOfferingOptions options = highlyAvailable(true); + assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("offerha")); + } + + public void testStorageType() { + CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().storageType(StorageType.LOCAL); + assertEquals(ImmutableSet.of("local"), options.buildQueryParameters().get("storagetype")); + } + + public void testStorageTypeStatic() { + CreateServiceOfferingOptions options = storageType(StorageType.LOCAL); + assertEquals(ImmutableSet.of("local"), options.buildQueryParameters().get("storagetype")); + } + + public void testSystemVmType() { + CreateServiceOfferingOptions options = + new CreateServiceOfferingOptions().systemVmType(SystemVmType.DOMAIN_ROUTER); + assertEquals(ImmutableSet.of("domainrouter"), options.buildQueryParameters().get("systemvmtype")); + } + + public void testSystemVmTypeStatic() { + CreateServiceOfferingOptions options = systemVmType(SystemVmType.DOMAIN_ROUTER); + assertEquals(ImmutableSet.of("domainrouter"), options.buildQueryParameters().get("systemvmtype")); + } + + public void testTags() { + CreateServiceOfferingOptions options = + new CreateServiceOfferingOptions().tags(ImmutableSet.of("tag1", "tag2")); + assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("tags")); + } + + public void testTagsStatic() { + CreateServiceOfferingOptions options = tags(ImmutableSet.of("tag1", "tag2")); + assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("tags")); + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptionsTest.java new file mode 100644 index 0000000000..97d1f365a9 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptionsTest.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.StorageType; +import org.jclouds.cloudstack.domain.SystemVmType; +import org.testng.annotations.Test; + +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.hostTags; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.isSystem; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.limitCpuUse; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.networkRateInMb; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.storageType; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.systemVmType; +import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.tags; +import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.displayText; +import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.name; +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@code UpdateServiceOfferingOptions} + * + * @author Andrei Savu + */ +@Test(groups = "unit") +public class UpdateServiceOfferingOptionsTest { + + public void testName() { + UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions().name("test-name"); + assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name")); + } + + public void testNameStatic() { + UpdateServiceOfferingOptions options = name("test-name"); + assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name")); + } + + public void testDisplayText() { + UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions().displayText("test-display-text"); + assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext")); + } + + public void testDisplayTextStatic() { + UpdateServiceOfferingOptions options = displayText("test-display-text"); + assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext")); + } + + +}