From 81f070738248bcda1ba4bc520419922db1568f0f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 20 Mar 2011 02:42:53 -0700 Subject: [PATCH] Issue 435: refactored savvis code --- .../org/jclouds/vcloud/xml/TaskHandler.java | 2 + core/src/main/resources/rest.properties | 3 + .../savvis-symphony-vpdc/pom.xml | 46 +- .../savvis/vpdc/SymphonyVPDCAsyncClient.java | 363 ------- .../jclouds/savvis/vpdc/VPDCAsyncClient.java | 41 + ...ymphonyVPDCClient.java => VPDCClient.java} | 26 +- ...xtBuilder.java => VPDCContextBuilder.java} | 17 +- ...uilder.java => VPDCPropertiesBuilder.java} | 10 +- .../VPDCComputeServiceContextModule.java | 53 + .../config/SymphonyVPDCRestClientModule.java | 83 -- .../vpdc/config/VPDCRestClientModule.java | 143 +++ .../org/jclouds/savvis/vpdc/domain/Link.java | 56 ++ .../jclouds/savvis/vpdc/domain/Network.java | 147 +++ .../org/jclouds/savvis/vpdc/domain/Org.java | 168 ++++ .../jclouds/savvis/vpdc/domain/Resource.java | 134 +++ .../vpdc/domain/ResourceAllocation.java | 279 ++++++ .../vpdc/domain/SymphonyVPDCNetwork.java | 85 -- .../org/jclouds/savvis/vpdc/domain/Task.java | 214 +++++ .../jclouds/savvis/vpdc/domain/TaskError.java | 136 +++ .../org/jclouds/savvis/vpdc/domain/VApp.java | 251 +++++ .../org/jclouds/savvis/vpdc/domain/VDC.java | 218 +++++ .../internal/SymphonyVPDCNetworkImpl.java | 205 ---- .../domain/internal/SymphonyVPDCVDCImpl.java | 75 -- .../internal/VCloudSession.java} | 12 +- .../savvis/vpdc/domain/vapp/Network.java | 59 ++ .../vpdc/domain/vapp/NetworkSection.java | 71 ++ .../vpdc/features/BrowsingAsyncClient.java | 110 +++ .../savvis/vpdc/features/BrowsingClient.java | 105 ++ .../vpdc/filters/SetVCloudTokenCookie.java | 53 + .../vpdc/functions/DefaultOrgIfNull.java | 48 + .../ParseLoginResponseFromHeaders.java | 76 ++ ...rrorHandler.java => VPDCErrorHandler.java} | 2 +- .../vpdc/internal/LoginAsyncClient.java | 51 + .../jclouds/savvis/vpdc/internal/Network.java | 40 + .../org/jclouds/savvis/vpdc/internal/Org.java | 40 + .../VCloudToken.java} | 22 +- .../org/jclouds/savvis/vpdc/internal/VDC.java | 40 + .../savvis/vpdc/predicates/TaskSuccess.java | 42 + .../vpdc/reference/VCloudConstants.java | 41 + .../vpdc/reference/VCloudMediaType.java | 207 ++++ .../org/jclouds/savvis/vpdc/util/Utils.java | 72 ++ .../savvis/vpdc/xml/NetworkHandler.java | 80 ++ .../vpdc/xml/NetworkSectionHandler.java | 58 ++ .../jclouds/savvis/vpdc/xml/OrgHandler.java | 83 ++ .../savvis/vpdc/xml/OrgListHandler.java | 39 + .../vpdc/xml/ResourceAllocationHandler.java | 59 ++ .../vpdc/xml/SymphonyVPDCNetworkHandler.java | 154 --- .../vpdc/xml/SymphonyVPDCVAppHandler.java | 147 --- .../vpdc/xml/SymphonyVPDCVDCHandler.java | 58 -- .../jclouds/savvis/vpdc/xml/TaskHandler.java | 106 ++ .../savvis/vpdc/xml/TasksListHandler.java | 68 ++ .../jclouds/savvis/vpdc/xml/VAppHandler.java | 111 +++ .../jclouds/savvis/vpdc/xml/VDCHandler.java | 83 ++ .../vpdc/SymphonyVPDCAsyncClientTest.java | 903 ------------------ .../vpdc/SymphonyVPDCClientLiveTest.java | 326 ------- .../savvis/vpdc/VPDCAsyncClientTest.java | 71 ++ .../SymphonyVPDCComputeServiceLiveTest.java | 57 -- .../SymphonyVPDCTemplateBuilderLiveTest.java | 77 -- .../features/BaseVPDCAsyncClientTest.java | 99 ++ .../vpdc/features/BaseVPDCClientLiveTest.java | 85 ++ .../features/BrowsingAsyncClientTest.java | 195 ++++ .../vpdc/features/BrowsingClientLiveTest.java | 132 +++ .../filters/SetVCloudTokenCookieTest.java | 59 ++ ...lerTest.java => VPDCErrorHandlerTest.java} | 4 +- .../savvis/vpdc/xml/NetworkHandlerTest.java | 75 ++ .../savvis/vpdc/xml/OrgHandlerTest.java | 28 +- .../savvis/vpdc/xml/OrgListHandlerTest.java | 56 ++ .../xml/ResourceAllocationHandlerTest.java | 32 + .../vpdc/xml/SymphonyVPDCVDCHandlerTest.java | 93 -- .../savvis/vpdc/xml/TaskHandlerTest.java | 248 +++++ .../savvis/vpdc/xml/VDCHandlerTest.java | 194 ++++ .../src/test/resources/log4j.xml | 170 ++++ .../src/test/resources/network-nat.xml | 18 + .../src/test/resources/network-unused.xml | 14 + .../src/test/resources/network.xml | 10 + .../src/test/resources/{savvis => }/org.xml | 0 .../src/test/resources/orglist.xml | 4 + .../src/test/resources/resourceallocation.xml | 26 + .../src/test/resources/task-error.xml | 11 + .../src/test/resources/task-failed.xml | 14 + .../src/test/resources/task-queued.xml | 15 + .../src/test/resources/task-running.xml | 15 + .../src/test/resources/task-unsupported.xml | 12 + .../src/test/resources/task-vapp.xml | 14 + .../src/test/resources/task-vmdk.xml | 14 + .../src/test/resources/vdc-1net.xml | 14 + .../src/test/resources/vdc-failed.xml | 11 + .../src/test/resources/vdc-saved.xml | 14 + .../src/test/resources/{savvis => }/vdc.xml | 2 +- 89 files changed, 5287 insertions(+), 2717 deletions(-) delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClient.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java rename sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/{SymphonyVPDCClient.java => VPDCClient.java} (65%) rename sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/{SymphonyVPDCContextBuilder.java => VPDCContextBuilder.java} (63%) rename sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/{SymphonyVPDCPropertiesBuilder.java => VPDCPropertiesBuilder.java} (74%) create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/SymphonyVPDCRestClientModule.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/ResourceAllocation.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/SymphonyVPDCNetwork.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VApp.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCNetworkImpl.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCVDCImpl.java rename sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/{compute/config/SymphonyVPDCComputeServiceContextModule.java => domain/internal/VCloudSession.java} (77%) create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/NetworkSection.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java rename sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/{SymphonyVPDCErrorHandler.java => VPDCErrorHandler.java} (97%) create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java rename sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/{domain/SymphonyVPDCVDC.java => internal/VCloudToken.java} (65%) create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudConstants.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkSectionHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandler.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCNetworkHandler.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVAppHandler.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VAppHandler.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClientTest.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCClientLiveTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCTemplateBuilderLiveTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java rename sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/{SymphonyVPDCErrorHandlerTest.java => VPDCErrorHandlerTest.java} (96%) create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandlerTest.java delete mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandlerTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/log4j.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-nat.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-unused.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/network.xml rename sandbox-providers/savvis-symphony-vpdc/src/test/resources/{savvis => }/org.xml (100%) create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/orglist.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/resourceallocation.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-error.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-failed.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-queued.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-running.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-unsupported.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vapp.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vmdk.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-1net.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-failed.xml create mode 100644 sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-saved.xml rename sandbox-providers/savvis-symphony-vpdc/src/test/resources/{savvis => }/vdc.xml (88%) diff --git a/common/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java b/common/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java index 7d2fdfe6b9..602274b4a3 100644 --- a/common/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java +++ b/common/vcloud/src/main/java/org/jclouds/vcloud/xml/TaskHandler.java @@ -25,6 +25,7 @@ import java.text.ParseException; import java.util.Date; import java.util.Map; +import javax.annotation.Resource; import javax.inject.Inject; import org.jclouds.date.DateService; @@ -55,6 +56,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult { private VCloudError error; private boolean inOwner; + @Resource protected Logger logger = Logger.NULL; @Inject diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index d3c5a8770a..1b2d272f74 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -157,6 +157,9 @@ cloudstack.propertiesbuilder=org.jclouds.cloudstack.CloudStackPropertiesBuilder softlayer.contextbuilder=org.jclouds.softlayer.SoftLayerContextBuilder softlayer.propertiesbuilder=org.jclouds.softlayer.SoftLayerPropertiesBuilder +savvis-symphonyvpdc.contextbuilder=org.jclouds.savvis.vpdc.VPDCContextBuilder +savvis-symphonyvpdc.propertiesbuilder=org.jclouds.savvis.vpdc.VPDCPropertiesBuilder + cloudfiles-us.contextbuilder=org.jclouds.cloudfiles.CloudFilesContextBuilder cloudfiles-us.propertiesbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesUSPropertiesBuilder diff --git a/sandbox-providers/savvis-symphony-vpdc/pom.xml b/sandbox-providers/savvis-symphony-vpdc/pom.xml index d9c357c863..acc3402847 100644 --- a/sandbox-providers/savvis-symphony-vpdc/pom.xml +++ b/sandbox-providers/savvis-symphony-vpdc/pom.xml @@ -31,9 +31,9 @@ ../../project/pom.xml org.jclouds.provider - savvis-symphony-vpdc - jclouds savvis core - jclouds components to access savvis + savvis-symphonyvpdc + jclouds savvis-vpdc vpdc + jclouds components to access Savvis Symphony VPDC @@ -52,34 +52,20 @@ node-924 - https://api.sandbox.symphonyVPDC.savvis.net/rest/api - 0.8 - FIXME - FIXME + https://api.symphonyvpdc.savvis.net/rest/api + 0.8 + FIXME + FIXME - - org.jclouds.api - vcloudexpress - ${project.version} - - - org.jclouds.api - vcloudexpress - ${project.version} - test-jar - test - org.jclouds jclouds-compute ${project.version} - test-jar - test org.jclouds - jclouds-vcloud + jclouds-compute ${project.version} test-jar test @@ -133,20 +119,20 @@ - test.savvis-symphony-vpdc.endpoint - ${test.savvis-symphony-vpdc.endpoint} + test.savvis-symphonyvpdc.endpoint + ${test.savvis-symphonyvpdc.endpoint} - test.savvis-symphony-vpdc.apiversion - ${test.savvis-symphony-vpdc.apiversion} + test.savvis-symphonyvpdc.apiversion + ${test.savvis-symphonyvpdc.apiversion} - test.savvis-symphony-vpdc.identity - ${test.savvis-symphony-vpdc.identity} + test.savvis-symphonyvpdc.identity + ${test.savvis-symphonyvpdc.identity} - test.savvis-symphony-vpdc.credential - ${test.savvis-symphony-vpdc.credential} + test.savvis-symphonyvpdc.credential + ${test.savvis-symphonyvpdc.credential} jclouds.compute.blacklist-nodes diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClient.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClient.java deleted file mode 100644 index 2a6f8f6954..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClient.java +++ /dev/null @@ -1,363 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc; - -import java.net.URI; - -import javax.annotation.Nullable; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import org.jclouds.predicates.validators.DnsNameValidator; -import org.jclouds.rest.annotations.EndpointParam; -import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.ParamValidators; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.savvis.vpdc.domain.SymphonyVPDCVDC; -import org.jclouds.savvis.vpdc.xml.SymphonyVPDCNetworkHandler; -import org.jclouds.savvis.vpdc.xml.SymphonyVPDCVAppHandler; -import org.jclouds.savvis.vpdc.xml.SymphonyVPDCVDCHandler; -import org.jclouds.vcloud.CommonVCloudClient; -import org.jclouds.vcloud.VCloudExpressAsyncClient; -import org.jclouds.vcloud.VCloudExpressClient; -import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload; -import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload; -import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.TasksList; -import org.jclouds.vcloud.domain.VCloudExpressVApp; -import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; -import org.jclouds.vcloud.domain.network.OrgNetwork; -import org.jclouds.vcloud.filters.SetVCloudTokenCookie; -import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameToEndpoint; -import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint; -import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint; -import org.jclouds.vcloud.options.CloneVAppOptions; -import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; -import org.jclouds.vcloud.xml.CatalogHandler; -import org.jclouds.vcloud.xml.CatalogItemHandler; -import org.jclouds.vcloud.xml.OrgHandler; -import org.jclouds.vcloud.xml.TaskHandler; -import org.jclouds.vcloud.xml.TasksListHandler; -import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; -import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler; - -import com.google.common.util.concurrent.ListenableFuture; - -/** - * Provides access to Symphony VPDC resources via their REST API. - *

- * - * @see - * @author Adrian Cole - */ -@RequestFilters(SetVCloudTokenCookie.class) -public interface SymphonyVPDCAsyncClient extends VCloudExpressAsyncClient { - - /** - * {@inheritDoc} - */ - @GET - // no accept header - @XMLResponseParser(OrgHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture findOrgNamed( - @Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName); - - /** - * {@inheritDoc} - */ - - @GET - // no accept header - @XMLResponseParser(OrgHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getOrg(@EndpointParam URI orgId); - - /** - * @see CommonVCloudClient#getVDC(URI) - */ - @GET - // no accept header - @XMLResponseParser(SymphonyVPDCVDCHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getVDC(@EndpointParam URI vdc); - - /** - * @see CommonVCloudClient#findVDCInOrgNamed(String, String) - */ - @GET - // no accept header - @XMLResponseParser(SymphonyVPDCVDCHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture findVDCInOrgNamed( - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); - - /** - * @see CommonVCloudClient#findNetworkInOrgVDCNamed - */ - @GET - // no accept header - @XMLResponseParser(SymphonyVPDCNetworkHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture findNetworkInOrgVDCNamed( - @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, - @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName); - - /** - * @see CommonVCloudClient#getNetwork - */ - @GET - // no accept header - @XMLResponseParser(SymphonyVPDCNetworkHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getNetwork(@EndpointParam URI network); - - /** - * @see VCloudClient#getVApp - */ - @GET - // no accept header - @XMLResponseParser(SymphonyVPDCVAppHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getVApp(@EndpointParam URI vApp); - - /** - * @see VCloudClient#getVAppTemplate - */ - @GET - // no accept header - @XMLResponseParser(VCloudExpressVAppTemplateHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getVAppTemplate(@EndpointParam URI vAppTemplate); - - /** - * @see VCloudClient#findVAppTemplateInOrgCatalogNamed - */ - @GET - // no accept header - @XMLResponseParser(VCloudExpressVAppTemplateHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture findVAppTemplateInOrgCatalogNamed( - @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName, - @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); - - /** - * @see VCloudExpressClient#instantiateVAppTemplateInVDC - */ - @POST - @Path("/action/instantiateVAppTemplate") - @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") - // no accept header - @XMLResponseParser(VCloudExpressVAppHandler.class) - @MapBinder(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class) - @Override - ListenableFuture instantiateVAppTemplateInVDC(@EndpointParam URI vdc, - @PayloadParam("template") URI template, - @PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, - InstantiateVAppTemplateOptions... options); - - /** - * @see VCloudExpressClient#cloneVAppInVDC - */ - @POST - @Path("/action/cloneVApp") - @Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml") - // no accept header - @XMLResponseParser(TaskHandler.class) - @MapBinder(BindCloneVAppParamsToXmlPayload.class) - @Override - ListenableFuture cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("vApp") URI toClone, - @PayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, CloneVAppOptions... options); - - /** - * @see VCloudClient#findVAppInOrgVDCNamed - */ - @GET - // no accept header - @XMLResponseParser(VCloudExpressVAppHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture findVAppInOrgVDCNamed( - @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, - @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName); - - /** - * @see CommonVCloudClient#deployVApp - */ - @POST - // no accept header - @Path("/action/deploy") - @XMLResponseParser(TaskHandler.class) - @Override - ListenableFuture deployVApp(@EndpointParam URI vAppId); - - /** - * @see CommonVCloudClient#undeployVApp - */ - @POST - // no accept header - @Path("/action/undeploy") - @XMLResponseParser(TaskHandler.class) - @Override - ListenableFuture undeployVApp(@EndpointParam URI vAppId); - - /** - * @see CommonVCloudClient#powerOnVApp - */ - @POST - // no accept header - @Path("/power/action/powerOn") - @XMLResponseParser(TaskHandler.class) - @Override - ListenableFuture powerOnVApp(@EndpointParam URI vAppId); - - /** - * @see CommonVCloudClient#powerOffVApp - */ - @POST - // no accept header - @Path("/power/action/powerOff") - @XMLResponseParser(TaskHandler.class) - @Override - ListenableFuture powerOffVApp(@EndpointParam URI vAppId); - - /** - * @see CommonVCloudClient#resetVApp - */ - @POST - // no accept header - @Path("/power/action/reset") - @XMLResponseParser(TaskHandler.class) - @Override - ListenableFuture resetVApp(@EndpointParam URI vAppId); - - /** - * @see CommonVCloudClient#suspendVApp - */ - @POST - // no accept header - @Path("/power/action/suspend") - @XMLResponseParser(TaskHandler.class) - @Override - ListenableFuture suspendVApp(@EndpointParam URI vAppId); - - /** - * @see CommonVCloudClient#getCatalog - */ - @GET - @XMLResponseParser(CatalogHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - // no accept header - @Override - ListenableFuture getCatalog(@EndpointParam URI catalogId); - - /** - * @see CommonVCloudClient#findCatalogInOrgNamed - */ - @GET - @XMLResponseParser(CatalogHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - // no accept header - @Override - ListenableFuture findCatalogInOrgNamed( - @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName); - - /** - * @see CommonVCloudClient#getCatalogItem - */ - @GET - // no accept header - @XMLResponseParser(CatalogItemHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getCatalogItem(@EndpointParam URI catalogItem); - - /** - * @see CommonVCloudClient#getCatalogItemInOrg - */ - @GET - // no accept header - @XMLResponseParser(CatalogItemHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture findCatalogItemInOrgCatalogNamed( - @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName, - @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName, - @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); - - /** - * @see CommonVCloudClient#getTasksList - */ - @GET - // no accept header - @XMLResponseParser(TasksListHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getTasksList(@EndpointParam URI tasksListId); - - /** - * @see CommonVCloudClient#findTasksListInOrgNamed - */ - @GET - // no accept header - @XMLResponseParser(TasksListHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture findTasksListInOrgNamed( - @Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName); - - /** - * @see CommonVCloudClient#getTask - */ - @GET - // no accept header - @XMLResponseParser(TaskHandler.class) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Override - ListenableFuture getTask(@EndpointParam URI taskId); - -} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java new file mode 100644 index 0000000000..4320855b96 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCAsyncClient.java @@ -0,0 +1,41 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc; + +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient; + +/** + * Provides asynchronous access to VPDC via their REST API. + *

+ * + * @see VPDCClient + * @see + * @author Adrian Cole + */ +public interface VPDCAsyncClient { + + /** + * Provides asynchronous access to Browsing features. + */ + @Delegate + BrowsingAsyncClient getBrowsingClient(); + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCClient.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java similarity index 65% rename from sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCClient.java rename to sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java index 236c990cb3..379e16c26e 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCClient.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCClient.java @@ -19,25 +19,27 @@ package org.jclouds.savvis.vpdc; -import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.savvis.vpdc.domain.SymphonyVPDCVDC; -import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.savvis.vpdc.features.BrowsingClient; /** - * Provides access to Symphony VPDC resources via their REST API. + * Provides synchronous access to VPDC. *

* - * @see + * @see VPDCAsyncClient + * @see * @author Adrian Cole */ -@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) -public interface SymphonyVPDCClient extends VCloudExpressClient { - @Override - SymphonyVPDCVDC findVDCInOrgNamed(String orgName, String vdcName); +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface VPDCClient { - @Override - SymphonyVPDCVDC getVDC(URI vdc); -} \ No newline at end of file + /** + * Provides synchronous access to Browsing features. + */ + @Delegate + BrowsingClient getBrowsingClient(); + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCContextBuilder.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java similarity index 63% rename from sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCContextBuilder.java rename to sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java index aa06ef4c39..dd4533340b 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCContextBuilder.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCContextBuilder.java @@ -23,8 +23,7 @@ import java.util.List; import java.util.Properties; import org.jclouds.compute.ComputeServiceContextBuilder; -import org.jclouds.savvis.vpdc.compute.config.SymphonyVPDCComputeServiceContextModule; -import org.jclouds.savvis.vpdc.config.SymphonyVPDCRestClientModule; +import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; import com.google.inject.Module; @@ -32,20 +31,14 @@ import com.google.inject.Module; * * @author Adrian Cole */ -public class SymphonyVPDCContextBuilder extends - ComputeServiceContextBuilder { +public class VPDCContextBuilder extends ComputeServiceContextBuilder { - public SymphonyVPDCContextBuilder(Properties props) { - super(SymphonyVPDCClient.class, SymphonyVPDCAsyncClient.class, props); - } - - @Override - protected void addContextModule(List modules) { - modules.add(new SymphonyVPDCComputeServiceContextModule()); + public VPDCContextBuilder(Properties props) { + super(VPDCClient.class, VPDCAsyncClient.class, props); } protected void addClientModule(List modules) { - modules.add(new SymphonyVPDCRestClientModule()); + modules.add(new VPDCRestClientModule()); } } diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCPropertiesBuilder.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java similarity index 74% rename from sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCPropertiesBuilder.java rename to sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java index 4240562f46..4ee290529b 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/SymphonyVPDCPropertiesBuilder.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/VPDCPropertiesBuilder.java @@ -21,26 +21,28 @@ package org.jclouds.savvis.vpdc; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.savvis.vpdc.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; import java.util.Properties; -import org.jclouds.vcloud.VCloudExpressPropertiesBuilder; +import org.jclouds.PropertiesBuilder; /** * Builds properties used in Symphony VPDC Clients * * @author Adrian Cole */ -public class SymphonyVPDCPropertiesBuilder extends VCloudExpressPropertiesBuilder { +public class VPDCPropertiesBuilder extends PropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_API_VERSION, "0.8"); - properties.setProperty(PROPERTY_ENDPOINT, "https://api.sandbox.symphonyVPDC.savvis.net/rest/api"); + properties.setProperty(PROPERTY_ENDPOINT, "https://api.symphonyvpdc.savvis.net/rest/api"); + properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 600l * 1000l + ""); return properties; } - public SymphonyVPDCPropertiesBuilder(Properties properties) { + public VPDCPropertiesBuilder(Properties properties) { super(properties); } diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java new file mode 100644 index 0000000000..cbcd0372d3 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/VPDCComputeServiceContextModule.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.compute.config; + +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.compute.config.BaseComputeServiceContextModule; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.savvis.vpdc.domain.VApp; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +public class VPDCComputeServiceContextModule extends BaseComputeServiceContextModule { + + @VisibleForTesting + public static final Map VAPPSTATUS_TO_NODESTATE = ImmutableMap + . builder().put(VApp.Status.OFF, NodeState.SUSPENDED) + .put(VApp.Status.ON, NodeState.RUNNING).put(VApp.Status.RESOLVED, NodeState.PENDING) + .put(VApp.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(VApp.Status.UNKNOWN, NodeState.UNRECOGNIZED) + .put(VApp.Status.SUSPENDED, NodeState.SUSPENDED).put(VApp.Status.UNRESOLVED, NodeState.PENDING).build(); + + @Singleton + @Provides + protected Map provideVAppStatusToNodeState() { + return VAPPSTATUS_TO_NODESTATE; + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/SymphonyVPDCRestClientModule.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/SymphonyVPDCRestClientModule.java deleted file mode 100644 index 24d40457b7..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/SymphonyVPDCRestClientModule.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.config; - -import java.net.URI; - -import javax.inject.Singleton; - -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.annotation.ClientError; -import org.jclouds.http.annotation.Redirection; -import org.jclouds.http.annotation.ServerError; -import org.jclouds.savvis.vpdc.SymphonyVPDCAsyncClient; -import org.jclouds.savvis.vpdc.SymphonyVPDCClient; -import org.jclouds.savvis.vpdc.handlers.SymphonyVPDCErrorHandler; -import org.jclouds.vcloud.VCloudExpressAsyncClient; -import org.jclouds.vcloud.VCloudExpressClient; -import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule; -import org.jclouds.vcloud.domain.Org; - -import com.google.inject.Provides; - -public class SymphonyVPDCRestClientModule extends - BaseVCloudExpressRestClientModule { - - public SymphonyVPDCRestClientModule() { - super(SymphonyVPDCClient.class, SymphonyVPDCAsyncClient.class); - } - - @Provides - @Singleton - protected VCloudExpressAsyncClient provideVCloudAsyncClient(SymphonyVPDCAsyncClient in) { - return in; - } - - @Provides - @Singleton - protected VCloudExpressClient provideVCloudClient(SymphonyVPDCClient in) { - return in; - } - - @Override - protected URI provideDefaultTasksList(Org org) { - if(org.getTasksList() != null){ - return org.getTasksList().getHref(); - }else{ - return URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/tasksList"); - } - } - - - @Override - protected void configure() { - super.configure(); -// no longer needed.. just here to show an example of how to override an xml handler -// bind(OrgListHandler.class).to(SymphonyVPDCOrgListHandler.class); - } - -@Override - protected void bindErrorHandlers() { - bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(SymphonyVPDCErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(SymphonyVPDCErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(SymphonyVPDCErrorHandler.class); - } - -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java new file mode 100644 index 0000000000..fd1269a8eb --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java @@ -0,0 +1,143 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.config; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Throwables.propagate; +import static org.jclouds.Constants.PROPERTY_IDENTITY; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.savvis.vpdc.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; + +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.rest.AsyncClientFactory; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; +import org.jclouds.savvis.vpdc.VPDCAsyncClient; +import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.internal.VCloudSession; +import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient; +import org.jclouds.savvis.vpdc.features.BrowsingClient; +import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler; +import org.jclouds.savvis.vpdc.internal.LoginAsyncClient; +import org.jclouds.savvis.vpdc.internal.VCloudToken; +import org.jclouds.savvis.vpdc.predicates.TaskSuccess; + +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import com.google.inject.Injector; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + * + */ +public class VPDCRestClientModule extends RestClientModule { + @Provides + @Singleton + protected LoginAsyncClient provideVCloudVersions(AsyncClientFactory factory) { + return factory.create(LoginAsyncClient.class); + } + + @VCloudToken + @Provides + String provideVCloudToken(Supplier cache) { + return checkNotNull(cache.get().getVCloudToken(), "No token present in session"); + } + + @Provides + @org.jclouds.savvis.vpdc.internal.Org + @Singleton + protected Iterable provideOrgs(Supplier cache, + @Named(PROPERTY_IDENTITY) String user) { + VCloudSession discovery = cache.get(); + checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user); + return discovery.getOrgs(); + } + + @Provides + @org.jclouds.savvis.vpdc.internal.Org + @Singleton + protected String provideDefaultOrgId(@org.jclouds.savvis.vpdc.internal.Org Iterable orgs) { + return Iterables.get(orgs, 0).getId(); + } + + protected AtomicReference authException = new AtomicReference(); + + @Provides + @Singleton + protected Predicate successTester(Injector injector, + @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { + return new RetryablePredicate(injector.getInstance(TaskSuccess.class), completed); + } + + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// + .put(BrowsingClient.class, BrowsingAsyncClient.class)// + .build(); + + public VPDCRestClientModule() { + super(VPDCClient.class, VPDCAsyncClient.class, DELEGATE_MAP); + } + + @Provides + @Singleton + protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + final LoginAsyncClient login) { + return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier(authException, seconds, + new Supplier() { + + @Override + public VCloudSession get() { + try { + return login.login().get(10, TimeUnit.SECONDS); + } catch (Exception e) { + propagate(e); + assert false : e; + return null; + } + } + + }); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(VPDCErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(VPDCErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(VPDCErrorHandler.class); + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java new file mode 100644 index 0000000000..0e1dd4f474 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Link.java @@ -0,0 +1,56 @@ +package org.jclouds.savvis.vpdc.domain; + +import java.net.URI; + +/** + * Location of a Rest resource + * + * @author Adrian Cole + * + */ +public class Link extends Resource { + protected final String rel; + + public Link( String id,String name, String type, URI href, String rel) { + super(id, name, type, href); + this.rel = rel; + } + + public String getRel() { + return rel; + } + + public int compareTo(Link that) { + return (this == that) ? 0 : getHref().compareTo(that.getHref()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((rel == null) ? 0 : rel.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + Link other = (Link) obj; + if (rel == null) { + if (other.rel != null) + return false; + } else if (!rel.equals(other.rel)) + return false; + return true; + } + + @Override + public String toString() { + return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", rel=" + rel + "]"; + } +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java new file mode 100644 index 0000000000..bd0fdea8b0 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Network.java @@ -0,0 +1,147 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Map; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +/** + * Various network features such NAT Public IP, Gateway and Netmask. + * + * @author Adrian Cole + */ +public class Network extends Resource { + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Resource.Builder { + private String gateway; + private String netmask; + private Map internalToExternalNATRules = Maps.newLinkedHashMap(); + + public Builder gateway(String gateway) { + this.gateway = gateway; + return this; + } + + public Builder netmask(String netmask) { + this.netmask = netmask; + return this; + } + + public Builder internalToExternalNATRule(String internalIP, String externalIP) { + this.internalToExternalNATRules.put(checkNotNull(internalIP, "internalIP"), + checkNotNull(externalIP, "externalIP")); + return this; + } + + public Builder internalToExternalNATRules(Map internalToExternalNATRules) { + this.internalToExternalNATRules.putAll(checkNotNull(internalToExternalNATRules, "internalToExternalNATRules")); + return this; + } + + @Override + public Network build() { + return new Network(id, name, type, href, gateway, netmask, internalToExternalNATRules); + } + + public static Builder fromOrg(Network in) { + return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) + .gateway(in.getGateway()).internalToExternalNATRules(in.getInternalToExternalNATRules()) + .netmask(in.getNetmask()); + } + + @Override + public Builder id(String id) { + return Builder.class.cast(super.id(id)); + } + + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + } + + @Nullable + private final String gateway; + private final String netmask; + private final Map internalToExternalNATRules; + + public Network(String id, String name, String type, URI href, @Nullable String gateway, String netmask, + Map internalToExternalNATRules) { + super(id, name, type, href); + this.gateway = gateway; + this.netmask = netmask; + this.internalToExternalNATRules = ImmutableMap.copyOf(checkNotNull(internalToExternalNATRules, + "internalToExternalNATRules")); + } + + /** + * @return IP of the network's gateway + */ + public String getGateway() { + return gateway; + } + + /** + * @return IP of the network's netmask + */ + public String getNetmask() { + return netmask; + } + + /** + * @return map of internal to external ip when it has any nat1to1 enabled deployed VApp + */ + public Map getInternalToExternalNATRules() { + return internalToExternalNATRules; + } + + @Override + public Builder toBuilder() { + return Builder.fromOrg(this); + } + + @Override + public String toString() { + return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", gateway=" + gateway + + ", netmask=" + netmask + ", internalToExternalNATRules=" + internalToExternalNATRules + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java new file mode 100644 index 0000000000..282a54143d --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Org.java @@ -0,0 +1,168 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +/** + * A cloud can contain one or more Organizations. There are two types of Organizations, hard-walled + * and soft-walled. + *

+ * + * @author Adrian Cole + */ +public class Org extends Resource { + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Resource.Builder { + private String description; + private Set vDCs = Sets.newLinkedHashSet(); + private Set images = Sets.newLinkedHashSet(); + + public Builder description(String description) { + this.description = description; + return this; + } + + public Builder vDC(Link vDC) { + this.vDCs.add(checkNotNull(vDC, "vDC")); + return this; + } + + public Builder vDCs(Set vDCs) { + this.vDCs.addAll(checkNotNull(vDCs, "vDCs")); + return this; + } + + public Builder image(Link image) { + this.images.add(checkNotNull(image, "image")); + return this; + } + + public Builder images(Set images) { + this.images.addAll(checkNotNull(images, "images")); + return this; + } + + @Override + public Org build() { + return new Org(id, name, type, href, description, vDCs, images); + } + + public static Builder fromOrg(Org in) { + return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) + .description(in.getDescription()).images(in.getImages()).vDCs(in.getVDCs()); + } + + @Override + public Builder id(String id) { + return Builder.class.cast(super.id(id)); + } + + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + } + + @Nullable + private final String description; + private final Set vDCs; + private final Set images; + + public Org(String id, String name, String type, URI href, @Nullable String description, Set vDCs, + Set images) { + super(id, name, type, href); + this.description = description; + this.vDCs = ImmutableSet.copyOf(checkNotNull(vDCs, "vDCs")); + this.images = ImmutableSet.copyOf(checkNotNull(images, "images")); + } + + /** + * {@inheritDoc} + */ + public String getName() { + return name; + } + + /** + * {@inheritDoc} + */ + public String getDescription() { + return description; + } + + /** + * {@inheritDoc} + */ + public Set getVDCs() { + return vDCs; + } + + /** + * {@inheritDoc} + */ + public Set getImages() { + return images; + } + + @Override + public Builder toBuilder() { + return Builder.fromOrg(this); + } + + @Override + public String toString() { + return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", description=" + description + + ", vDCs=" + vDCs + ", images=" + images + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java new file mode 100644 index 0000000000..8f3ac09192 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Resource.java @@ -0,0 +1,134 @@ +package org.jclouds.savvis.vpdc.domain; + +import java.net.URI; + +/** + * Location of a Rest resource + * + * @author Adrian Cole + * + */ +public class Resource { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + protected String id; + protected String name; + protected String type; + protected URI href; + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder type(String type) { + this.type = type; + return this; + } + + public Builder href(URI href) { + this.href = href; + return this; + } + + public Resource build() { + return new Resource(id, name, type, href); + } + + public static Builder fromResource(Resource in) { + return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()); + } + } + + protected final String id; + protected final String name; + protected final String type; + protected final URI href; + + public Resource(String id, String name, String type, URI href) { + this.id = id; + this.name = name; + this.type = type; + this.href = href; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public URI getHref() { + return href; + } + + public int compareTo(Resource that) { + return (this == that) ? 0 : getHref().compareTo(that.getHref()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((href == null) ? 0 : href.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Resource other = (Resource) obj; + if (href == null) { + if (other.href != null) + return false; + } else if (!href.equals(other.href)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + return true; + } + + public Builder toBuilder() { + return Builder.fromResource(this); + } + + @Override + public String toString() { + return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + "]"; + } +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/ResourceAllocation.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/ResourceAllocation.java new file mode 100644 index 0000000000..d87527b9c7 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/ResourceAllocation.java @@ -0,0 +1,279 @@ +package org.jclouds.savvis.vpdc.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Adrian Cole + * + */ +public class ResourceAllocation { + public enum Type { + /** + * 3 GHz equals 1 vCPU + *

+ * 1.5 Ghz equals 0.5 vCPU + */ + PROCESSOR, + /** + * Gigabytes + */ + MEMORY, ETHERNET_ADAPTER, + /** + * Gigabytes + */ + BOOT_DISK, + /** + * Gigabytes + */ + DATA_DISK, UNRECOGNIZED; + + public String value() { + switch (this) { + case PROCESSOR: + return "3"; + case MEMORY: + return "4"; + case ETHERNET_ADAPTER: + return "10"; + case BOOT_DISK: + return "27"; + case DATA_DISK: + return "26"; + default: + return "UNRECOGNIZED"; + } + } + + public static Type fromValue(String type) { + try { + return fromValue(Integer.parseInt(checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + + public static Type fromValue(int v) { + switch (v) { + case 3: + return PROCESSOR; + case 4: + return MEMORY; + case 10: + return ETHERNET_ADAPTER; + case 27: + return BOOT_DISK; + case 26: + return DATA_DISK; + default: + return UNRECOGNIZED; + } + } + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + protected int id; + protected Type type; + protected String name; + protected String description; + protected String allocationUnits; + protected long virtualQuantity; + protected String connection; + protected String caption; + protected String hostResource; + + public Builder id(int id) { + this.id = id; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder connection(String connection) { + this.connection = connection; + return this; + } + + public Builder caption(String caption) { + this.caption = caption; + return this; + } + + public Builder hostResource(String hostResource) { + this.hostResource = hostResource; + return this; + } + + public Builder description(String description) { + this.description = description; + return this; + } + + public Builder allocationUnits(String allocationUnits) { + this.allocationUnits = allocationUnits; + return this; + } + + public Builder type(Type type) { + this.type = type; + return this; + } + + public Builder virtualQuantity(long virtualQuantity) { + this.virtualQuantity = virtualQuantity; + return this; + } + + public ResourceAllocation build() { + return new ResourceAllocation(id, type, name, description, allocationUnits, virtualQuantity, connection, + caption, hostResource); + } + + public static Builder fromResourceAllocation(ResourceAllocation in) { + return new Builder().id(in.getId()).type(in.getType()).name(in.getName()).description(in.getDescription()) + .allocationUnits(in.getAllocationUnits()).virtualQuantity(in.getVirtualQuantity()) + .connection(in.getConnection()).caption(in.getCaption()).hostResource(in.getHostResource()); + } + } + + protected final int id; + protected final Type type; + protected final String name; + protected final String description; + protected final String allocationUnits; + protected final long virtualQuantity; + protected final String connection; + protected final String caption; + protected final String hostResource; + + public ResourceAllocation(int id, Type type, String name, String description, String allocationUnits, + long virtualQuantity, String connection, String caption, String hostResource) { + this.id = id; + this.type = checkNotNull(type, "type"); + this.name = checkNotNull(name, "name"); + this.description = description; + this.allocationUnits = allocationUnits; + this.virtualQuantity = virtualQuantity; + this.connection = connection; + this.caption = caption; + this.hostResource = hostResource; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public Type getType() { + return type; + } + + public String getAllocationUnits() { + return allocationUnits; + } + + public String getConnection() { + return connection; + } + + public String getCaption() { + return caption; + } + + public long getVirtualQuantity() { + return virtualQuantity; + } + + public String getHostResource() { + return hostResource; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((allocationUnits == null) ? 0 : allocationUnits.hashCode()); + result = prime * result + ((caption == null) ? 0 : caption.hashCode()); + result = prime * result + ((connection == null) ? 0 : connection.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((hostResource == null) ? 0 : hostResource.hashCode()); + result = prime * result + id; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + (int) (virtualQuantity ^ (virtualQuantity >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ResourceAllocation other = (ResourceAllocation) obj; + if (allocationUnits == null) { + if (other.allocationUnits != null) + return false; + } else if (!allocationUnits.equals(other.allocationUnits)) + return false; + if (caption == null) { + if (other.caption != null) + return false; + } else if (!caption.equals(other.caption)) + return false; + if (connection == null) { + if (other.connection != null) + return false; + } else if (!connection.equals(other.connection)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (hostResource == null) { + if (other.hostResource != null) + return false; + } else if (!hostResource.equals(other.hostResource)) + return false; + if (id != other.id) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (type != other.type) + return false; + if (virtualQuantity != other.virtualQuantity) + return false; + return true; + } + + public Builder toBuilder() { + return Builder.fromResourceAllocation(this); + } + + @Override + public String toString() { + return "[id=" + id + ", type=" + type + ", name=" + name + ", description=" + description + ", allocationUnits=" + + allocationUnits + ", virtualQuantity=" + virtualQuantity + ", connection=" + connection + ", caption=" + + caption + ", hostResource=" + hostResource + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/SymphonyVPDCNetwork.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/SymphonyVPDCNetwork.java deleted file mode 100644 index 818ac64e9a..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/SymphonyVPDCNetwork.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.domain; - -import java.util.Set; - -import javax.annotation.Nullable; - -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.network.FenceMode; -import org.jclouds.vcloud.domain.network.firewall.FirewallRule; -import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule; - -/** - * - * A network that is available in a vDC. - * - * @author Kedar Dave - */ -public interface SymphonyVPDCNetwork extends ReferenceType { - /** - * - * @return Description of the network - */ - String getDescription(); - - /** - * @return IP addresses of the network’s DNS servers. - */ - Set getDnsServers(); - - /** - * - * - * @return The IP address of the network’s primary gateway - */ - String getGateway(); - - /** - * * - * - * @return the network’s subnet mask - */ - String getNetmask(); - - /** - * return the network’s fence modes. - */ - Set getFenceModes(); - - /** - * return True if the network provides DHCP services - */ - @Nullable - Boolean isDhcp(); - - /** - * - * @return Network Address Translation rules for the network - */ - Set getNatRules(); - - /** - * @return Firewall rules for the network - */ - Set getFirewallRules(); - -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java new file mode 100644 index 0000000000..e34a9529f3 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/Task.java @@ -0,0 +1,214 @@ +package org.jclouds.savvis.vpdc.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Date; + +import javax.annotation.Nullable; + +/** + * The result of a client request cannot be returned immediately, the server creates a task entity + * and returns its URL to the client. The client can use this URL in a subsequent GET request to + * obtain the current status of the task. + * + * @see + */ +public class Task extends Resource { + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Resource.Builder { + private Status status; + private Date startTime; + private Date endTime; + private Resource owner; + private Resource result; + private TaskError error; + + public Builder status(Status status) { + this.status = status; + return this; + } + + public Builder startTime(Date startTime) { + this.startTime = startTime; + return this; + } + + public Builder endTime(Date endTime) { + this.endTime = endTime; + return this; + } + + public Builder owner(Resource owner) { + this.owner = owner; + return this; + } + + public Builder result(Resource result) { + this.result = result; + return this; + } + + public Builder error(TaskError error) { + this.error = error; + return this; + } + + @Override + public Builder id(String id) { + return Builder.class.cast(super.id(id)); + } + + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + @Override + public Task build() { + return new Task(id, name, type, href, status, startTime, endTime, owner, result, error); + } + + public static Builder fromTask(Task in) { + return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) + .status(in.getStatus()).startTime(in.getStartTime()).endTime(in.getEndTime()).owner(in.getOwner()) + .error(in.getError()).result(in.getResult()); + } + } + + public enum Status { + /** + * Savvis VPDC successfully provisioned and available for use. + */ + SUCCESS, + /** + * Savvis VPDC is processing the user request, please wait for the provisioning process to + * complete. + */ + RUNNING, + + /** + * Savvis VPDC is processing the user request, please wait for the provisioning process to + * complete. + */ + QUEUED, + /** + * Savvis VPDC is failed, please kindly contact Savvis administrator for further + * clarification/assistance with the respective request data. + */ + ERROR, + /** + * Unexpected Savvus VPDC Status, Savvis VPDC is failed, please kindly contact Savvis + * administrator for further clarification/assistance with the respective request data. + */ + NONE, UNRECOGNIZED; + public String value() { + return name().toLowerCase(); + } + + @Override + public String toString() { + return value(); + } + + public static Status fromValue(String status) { + try { + return valueOf(checkNotNull(status, "status").toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + + } + + private final Status status; + private final Date startTime; + private final Date endTime; + private final Resource owner; + private final Resource result; + private final TaskError error; + + public Task(String id, String name, String type, URI href, Status status, Date startTime, Date endTime, + Resource result, Resource owner, TaskError error) { + super(id, name, type, href); + this.status = status; + this.startTime = startTime; + this.endTime = endTime; + this.owner = owner; + this.result = result; + this.error = error; + } + + /** + * The current status of the task. + */ + public Status getStatus() { + return status; + } + + /** + * date and time when the task was started. + */ + public Date getStartTime() { + return startTime; + } + + /** + * date and time when the task completed. Does not appear for running tasks. + */ + @Nullable + public Date getEndTime() { + return endTime; + } + + /** + * A link to the object that owns the task. For copy operations, the owner is the copy that is + * being created. For delete operations, the owner is the deleted object, so this element is not + * included. For all other operations, the owner is the object to which the request was made. + */ + @Nullable + public Resource getOwner() { + return owner; + } + + /** + * Result is represent outcome of request url. if any VM related operation, the result will + * present as get VApp. if any VMDK related operation, the result will present as get VMKD + */ + @Nullable + public Resource getResult() { + return result; + } + + /** + * error message or related information returned by the task + */ + @Nullable + public TaskError getError() { + return error; + } + + public Builder toBuilder() { + return Builder.fromTask(this); + } + + @Override + public String toString() { + return "[status=" + status + ", startTime=" + startTime + ", endTime=" + endTime + ", owner=" + owner + + ", result=" + result + ", error=" + error + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java new file mode 100644 index 0000000000..2efdd9be90 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/TaskError.java @@ -0,0 +1,136 @@ +package org.jclouds.savvis.vpdc.domain; + +import javax.annotation.Nullable; + +/** + * + * + * @author Adrian Cole + */ +public class TaskError { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String message; + private int majorErrorCode = -1; + private int minorErrorCode = -1; + private String vendorSpecificErrorCode; + + public Builder message(String message) { + this.message = message; + return this; + } + + public Builder majorErrorCode(int majorErrorCode) { + this.majorErrorCode = majorErrorCode; + return this; + } + + public Builder minorErrorCode(int minorErrorCode) { + this.minorErrorCode = minorErrorCode; + return this; + } + + public Builder vendorSpecificErrorCode(String vendorSpecificErrorCode) { + this.vendorSpecificErrorCode = vendorSpecificErrorCode; + return this; + } + + public TaskError build() { + return new TaskError(message, majorErrorCode, minorErrorCode, vendorSpecificErrorCode); + } + } + + private final String message; + private final int majorErrorCode; + private final int minorErrorCode; + private final String vendorSpecificErrorCode; + + public TaskError(String message, int majorErrorCode, int minorErrorCode, @Nullable String vendorSpecificErrorCode) { + this.message = message; + this.majorErrorCode = majorErrorCode; + this.minorErrorCode = minorErrorCode; + this.vendorSpecificErrorCode = vendorSpecificErrorCode; + } + + /** + * + * @return message describing the error + */ + public String getMessage() { + return message; + } + + /** + * + * @return matches the HTTP status code + */ + public int getMajorErrorCode() { + return majorErrorCode; + } + + /** + * + * @return matches the minor code, typically -1 + */ + public int getMinorErrorCode() { + return minorErrorCode; + } + + /** + * + * @return optional additional information about the source of the error + */ + @Nullable + public String getVendorSpecificErrorCode() { + return vendorSpecificErrorCode; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + majorErrorCode; + result = prime * result + ((message == null) ? 0 : message.hashCode()); + result = prime * result + minorErrorCode; + result = prime * result + ((vendorSpecificErrorCode == null) ? 0 : vendorSpecificErrorCode.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TaskError other = (TaskError) obj; + if (majorErrorCode != other.majorErrorCode) + return false; + if (message == null) { + if (other.message != null) + return false; + } else if (!message.equals(other.message)) + return false; + if (minorErrorCode != other.minorErrorCode) + return false; + if (vendorSpecificErrorCode == null) { + if (other.vendorSpecificErrorCode != null) + return false; + } else if (!vendorSpecificErrorCode.equals(other.vendorSpecificErrorCode)) + return false; + return true; + } + + @Override + public String toString() { + return "[message=" + message + ", majorErrorCode=" + majorErrorCode + ", minorErrorCode=" + minorErrorCode + + ", vendorSpecificErrorCode=" + vendorSpecificErrorCode + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VApp.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VApp.java new file mode 100644 index 0000000000..69f566d013 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VApp.java @@ -0,0 +1,251 @@ +package org.jclouds.savvis.vpdc.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.savvis.vpdc.domain.vapp.NetworkSection; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +/** + * A virtual application (vApp) is a software solution, packaged in OVF containing one or more + * virtual machines. A vApp can be authored by Developers at ISVs and VARs or by IT Administrators + * in Enterprises and Service Providers. + * + * @author Adrian Cole + */ +public class VApp extends Resource { + /** + * Objects such as vAppTemplate, vApp, and Vm have a status attribute whose value indicates the + * state of the object. Status for an object, such as a vAppTemplate or vApp, whose Children (Vm + * objects) each have a status of their own, is computed from the status of the Children. + * + *

NOTE

+ *

+ * The deployment status of an object is indicated by the value of its deployed attribute. + * + * @since vcloud api 0.8 + * + * @author Adrian Cole + */ + public enum Status { + + /** + * When the VM is in Designing,Saved,Inqueue, has issue in pre provisioning or any exception + * cases. VM is not in Savvis VPDC (may the VM has been removed) or cannot get VM state due to + * unknown exception + */ + UNRESOLVED, + /** + * When the Savvis VPDC is in Provisioning, PartiallyDeployed, Failed and the VM failed in + * provisioning or pending infrastructure notification + */ + RESOLVED, + /** + * When the VM is deployed in vmware and powered off. + */ + OFF, + /** + * We do not support suspended state. + */ + SUSPENDED, + /** + * When the VM is deployed in vmware and powered on. + */ + ON, + /** + * The VM is deployed in vmware but the state of VM may be Uninitialized, Start, Stop, Resume, + * Reset, RebootGuest, Error, Failed, Unknown, PoweringOn, PoweringOff, Suspending, Stopping, + * Starting, Resetting, RebootingGuest. Please call back the Get VApp Power State API after + * few minute. + */ + UNKNOWN, UNRECOGNIZED; + + public String value() { + switch (this) { + case UNRESOLVED: + return "0"; + case RESOLVED: + return "1"; + case OFF: + return "2"; + case SUSPENDED: + return "3"; + case ON: + return "4"; + case UNKNOWN: + return "5"; + default: + return "UNRECOGNIZED"; + } + } + + public static Status fromValue(String status) { + try { + return fromValue(Integer.parseInt(checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + + public static Status fromValue(int v) { + switch (v) { + case 0: + return UNRESOLVED; + case 1: + return RESOLVED; + case 2: + return OFF; + case 3: + return SUSPENDED; + case 4: + return ON; + case 5: + return UNKNOWN; + default: + return UNRECOGNIZED; + } + } + + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Resource.Builder { + private Status status; + private String ipAddress; + private Integer osType; + private String osDescripton; + private NetworkSection networkSection; + private Set resourceAllocations = Sets.newLinkedHashSet(); + + public Builder ipAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + public Builder status(Status status) { + this.status = status; + return this; + } + + public Builder osType(Integer osType) { + this.osType = osType; + return this; + } + + public Builder networkSection(NetworkSection networkSection) { + this.networkSection = networkSection; + return this; + } + + public Builder osDescripton(String osDescripton) { + this.osDescripton = osDescripton; + return this; + } + + public Builder resourceAllocation(ResourceAllocation in) { + this.resourceAllocations.add(checkNotNull(in, "resourceAllocation")); + return this; + } + + public Builder resourceAllocations(Set resourceAllocations) { + this.resourceAllocations.addAll(checkNotNull(resourceAllocations, "resourceAllocations")); + return this; + } + + @Override + public VApp build() { + return new VApp(id, name, type, href, status, ipAddress, osType, osDescripton, networkSection, + resourceAllocations); + } + + public static Builder fromVApp(VApp in) { + return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) + .status(in.getStatus()).ipAddress(in.getIpAddress()).osType(in.getOsType()) + .networkSection(in.getNetworkSection()).resourceAllocations(in.getResourceAllocations()) + .osDescripton(in.getOsDescripton()); + } + + @Override + public Builder id(String id) { + return Builder.class.cast(super.id(id)); + } + + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + } + + private final Status status; + private final String ipAddress; + private final Integer osType; + private final String osDescripton; + private final NetworkSection networkSection; + private final Set resourceAllocations; + + public VApp(String id, String name, String type, URI href, Status status, String ipAddress, Integer osType, + String osDescripton, NetworkSection networkSection, Set resourceAllocations) { + super(id, name, type, href); + this.status = status; + this.ipAddress = ipAddress; + this.osType = osType; + this.osDescripton = osDescripton; + this.networkSection = networkSection; + this.resourceAllocations = ImmutableSet.copyOf(checkNotNull(resourceAllocations, "resourceAllocations")); + } + + public Status getStatus() { + return status; + } + + public String getIpAddress() { + return ipAddress; + } + + public Integer getOsType() { + return osType; + } + + public String getOsDescripton() { + return osDescripton; + } + + public NetworkSection getNetworkSection() { + return networkSection; + } + + public Set getResourceAllocations() { + return resourceAllocations; + } + + @Override + public Builder toBuilder() { + return Builder.fromVApp(this); + } + + @Override + public String toString() { + return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", status=" + status + + ", ipAddress=" + ipAddress + ", osType=" + osType + ", osDescripton=" + osDescripton + + ", networkSection=" + networkSection + ", resourceAllocations=" + resourceAllocations + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java new file mode 100644 index 0000000000..6a970aa1ef --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/VDC.java @@ -0,0 +1,218 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.base.CaseFormat; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +/** + * VDC is a virtual data center ,the API returns a list of VAPPs own by given bill site Id. + * + * @author Adrian Cole + */ +public class VDC extends Resource { + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Resource.Builder { + private String description; + private Status status; + private Set resourceEntities = Sets.newLinkedHashSet(); + private Set availableNetworks = Sets.newLinkedHashSet(); + + public Builder description(String description) { + this.description = description; + return this; + } + + public Builder status(Status status) { + this.status = status; + return this; + } + + public Builder resourceEntity(Resource resourceEntity) { + this.resourceEntities.add(checkNotNull(resourceEntity, "resourceEntity")); + return this; + } + + public Builder resourceEntities(Set resourceEntities) { + this.resourceEntities.addAll(checkNotNull(resourceEntities, "resourceEntities")); + return this; + } + + public Builder availableNetwork(Resource availableNetwork) { + this.availableNetworks.add(checkNotNull(availableNetwork, "availableNetwork")); + return this; + } + + public Builder availableNetworks(Set availableNetworks) { + this.availableNetworks.addAll(checkNotNull(availableNetworks, "availableNetworks")); + return this; + } + + @Override + public VDC build() { + return new VDC(id, name, type, href, description, status, resourceEntities, availableNetworks); + } + + public static Builder fromVDC(VDC in) { + return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) + .status(in.getStatus()).description(in.getDescription()).availableNetworks(in.getAvailableNetworks()) + .resourceEntities(in.getResourceEntities()); + } + + @Override + public Builder id(String id) { + return Builder.class.cast(super.id(id)); + } + + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + } + + public enum Status { + /** + * Savvis VPDC successfully provisioned and available for use + */ + DEPLOYED, + /** + * Savvis VPDC need to be provisioned and cannot invoke any of the VCloud (post request method + * type) API's + */ + DESIGNING, + /** + * Savvis VPDC need to be provisioned and cannot invoke any of the VCloud (post request method + * type) API's + */ + SAVED, + /** + * Please wait for the provisioning process to complete and cannot invoke any of the VCloud + * (post request method type) API's + */ + INQUEUE, + /** + * Please wait for the provisioning process to complete and cannot invoke any of the VCloud + * (post request method type) API's + */ + PROVISIONING, + /** + * Please kindly contact Savvis administrator for further clarification/assistance with the + * respective request data. and cannot invoke any of the VCloud (post request method type) + * API's + */ + PARTIALLY_DEPLOYED, + /** + * Please kindly contact Savvis administrator for further clarification/assistance with the + * respective request data and cannot invoke any of the VCloud (post request method type) + * API's + */ + FAILED, UNRECOGNIZED; + @Override + public String toString() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + public static Status fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + @Nullable + private final String description; + private final VDC.Status status; + private final Set resourceEntities; + private final Set availableNetworks; + + public VDC(String id, String name, String type, URI href, @Nullable String description, VDC.Status status, + Set resourceEntities, Set availableNetworks) { + super(id, name, type, href); + this.description = description; + this.status = checkNotNull(status, "status"); + this.resourceEntities = ImmutableSet.copyOf(checkNotNull(resourceEntities, "resourceEntities")); + this.availableNetworks = ImmutableSet.copyOf(checkNotNull(availableNetworks, "availableNetworks")); + } + + /** + * {@inheritDoc} + */ + public String getDescription() { + return description; + } + + /** + * {@inheritDoc} + */ + public VDC.Status getStatus() { + return status; + } + + /** + * {@inheritDoc} + */ + public Set getResourceEntities() { + return resourceEntities; + } + + /** + * {@inheritDoc} + */ + public Set getAvailableNetworks() { + return availableNetworks; + } + + @Override + public Builder toBuilder() { + return Builder.fromVDC(this); + } + + @Override + public String toString() { + return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", description=" + description + + ", status=" + status + ", resourceEntities=" + resourceEntities + ", availableNetworks=" + + availableNetworks + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCNetworkImpl.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCNetworkImpl.java deleted file mode 100644 index 19510622fd..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCNetworkImpl.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.domain.internal; - -import java.net.URI; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.jclouds.savvis.vpdc.domain.SymphonyVPDCNetwork; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; -import org.jclouds.vcloud.domain.network.FenceMode; -import org.jclouds.vcloud.domain.network.firewall.FirewallRule; -import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule; - -import com.google.common.collect.Sets; - -/** - * Locations of resources in vCloud - * - * @author Kedar Dave - * - */ -public class SymphonyVPDCNetworkImpl extends ReferenceTypeImpl implements SymphonyVPDCNetwork { - - /** The serialVersionUID */ - private static final long serialVersionUID = 8464716396538298809L; - protected final String description; - protected final Set dnsServers = Sets.newHashSet(); - protected final String gateway; - protected final String netmask; - protected final Set fenceModes = Sets.newHashSet(); - @Nullable - protected final Boolean dhcp; - protected final Set natRules = Sets.newHashSet(); - protected final Set firewallRules = Sets.newHashSet(); - - public SymphonyVPDCNetworkImpl(String name, String type, URI id, String description, Set dnsServers, - String gateway, String netmask, Set fenceModes, Boolean dhcp, Set natRules, - Set firewallRules) { - super(name, type, id); - this.description = description; - this.dnsServers.addAll(dnsServers); - this.gateway = gateway; - this.netmask = netmask; - this.fenceModes.addAll(fenceModes); - this.dhcp = dhcp; - this.natRules.addAll(natRules); - this.firewallRules.addAll(firewallRules); - } - - /** - * {@inheritDoc} - */ - public String getDescription() { - return description; - } - - /** - * {@inheritDoc} - */ - public Set getDnsServers() { - return dnsServers; - } - - /** - * {@inheritDoc} - */ - public String getGateway() { - return gateway; - } - - /** - * {@inheritDoc} - */ - public String getNetmask() { - return netmask; - } - - /** - * {@inheritDoc} - */ - public Set getFenceModes() { - return fenceModes; - } - - /** - * {@inheritDoc} - */ - public Boolean isDhcp() { - return dhcp; - } - - /** - * {@inheritDoc} - */ - public Set getNatRules() { - return natRules; - } - - /** - * {@inheritDoc} - */ - public Set getFirewallRules() { - return firewallRules; - } - - @Override - public int compareTo(ReferenceType o) { - return (this == o) ? 0 : getHref().compareTo(o.getHref()); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((dhcp == null) ? 0 : dhcp.hashCode()); - result = prime * result + ((dnsServers == null) ? 0 : dnsServers.hashCode()); - result = prime * result + ((fenceModes == null) ? 0 : fenceModes.hashCode()); - result = prime * result + ((firewallRules == null) ? 0 : firewallRules.hashCode()); - result = prime * result + ((gateway == null) ? 0 : gateway.hashCode()); - result = prime * result + ((natRules == null) ? 0 : natRules.hashCode()); - result = prime * result + ((netmask == null) ? 0 : netmask.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - SymphonyVPDCNetworkImpl other = (SymphonyVPDCNetworkImpl) obj; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (dhcp == null) { - if (other.dhcp != null) - return false; - } else if (!dhcp.equals(other.dhcp)) - return false; - if (dnsServers == null) { - if (other.dnsServers != null) - return false; - } else if (!dnsServers.equals(other.dnsServers)) - return false; - if (fenceModes == null) { - if (other.fenceModes != null) - return false; - } else if (!fenceModes.equals(other.fenceModes)) - return false; - if (firewallRules == null) { - if (other.firewallRules != null) - return false; - } else if (!firewallRules.equals(other.firewallRules)) - return false; - if (gateway == null) { - if (other.gateway != null) - return false; - } else if (!gateway.equals(other.gateway)) - return false; - if (natRules == null) { - if (other.natRules != null) - return false; - } else if (!natRules.equals(other.natRules)) - return false; - if (netmask == null) { - if (other.netmask != null) - return false; - } else if (!netmask.equals(other.netmask)) - return false; - return true; - } - - @Override - public String toString() { - return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description - + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules=" - + firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" + netmask + "]"; - } - -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCVDCImpl.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCVDCImpl.java deleted file mode 100644 index 5a8d829b7f..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/SymphonyVPDCVDCImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.jclouds.savvis.vpdc.domain.internal; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.jclouds.savvis.vpdc.domain.SymphonyVPDCVDC; -import org.jclouds.vcloud.domain.AllocationModel; -import org.jclouds.vcloud.domain.Capacity; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.VDCStatus; -import org.jclouds.vcloud.domain.internal.VDCImpl; - -/** - * Locations of resources in SymphonyVPDC vDC - * - * @author Adrian Cole - * - */ -public class SymphonyVPDCVDCImpl extends VDCImpl implements SymphonyVPDCVDC { - private final String offeringTag; - - /** The serialVersionUID */ - private static final long serialVersionUID = 8464716396538298809L; - - public SymphonyVPDCVDCImpl(String name, String type, URI id, VDCStatus status, ReferenceType org, - @Nullable String description, Iterable tasks, AllocationModel allocationModel, - @Nullable Capacity storageCapacity, @Nullable Capacity cpuCapacity, @Nullable Capacity memoryCapacity, - Map resourceEntities, Map availableNetworks, int nicQuota, - int networkQuota, int vmQuota, boolean isEnabled, String offeringTag) { - super(name, type, id, status, org, description, tasks, allocationModel, storageCapacity, cpuCapacity, - memoryCapacity, resourceEntities, availableNetworks, nicQuota, networkQuota, vmQuota, isEnabled); - this.offeringTag = checkNotNull(offeringTag, "offeringTag"); - } - - @Override - public String getOfferingTag() { - return offeringTag; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((offeringTag == null) ? 0 : offeringTag.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - SymphonyVPDCVDCImpl other = (SymphonyVPDCVDCImpl) obj; - if (offeringTag == null) { - if (other.offeringTag != null) - return false; - } else if (!offeringTag.equals(other.offeringTag)) - return false; - return true; - } - - @Override - public String toString() { - return "[id=" + getHref() + ", name=" + getName() + ", description=" + getDescription() + ", offeringTag=" - + offeringTag + "]"; - } -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/SymphonyVPDCComputeServiceContextModule.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/VCloudSession.java similarity index 77% rename from sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/SymphonyVPDCComputeServiceContextModule.java rename to sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/VCloudSession.java index ce962be795..ebbf14fc87 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/compute/config/SymphonyVPDCComputeServiceContextModule.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/internal/VCloudSession.java @@ -17,14 +17,18 @@ * ==================================================================== */ -package org.jclouds.savvis.vpdc.compute.config; +package org.jclouds.savvis.vpdc.domain.internal; -import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule; +import java.util.Set; + +import org.jclouds.savvis.vpdc.domain.Resource; /** * * @author Adrian Cole */ -public class SymphonyVPDCComputeServiceContextModule extends VCloudExpressComputeServiceContextModule { +public interface VCloudSession { + String getVCloudToken(); -} + Set getOrgs(); +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java new file mode 100644 index 0000000000..9f65e6386e --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/Network.java @@ -0,0 +1,59 @@ +package org.jclouds.savvis.vpdc.domain.vapp; + +/** + * + * @author Adrian Cole + */ +public class Network { + private final String name; + private final String description; + + public Network(String name, String description) { + this.name = name; + this.description = description; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Network other = (Network) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + return "Network [name=" + name + ", description=" + description + "]"; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/NetworkSection.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/NetworkSection.java new file mode 100644 index 0000000000..b99c363bd5 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/vapp/NetworkSection.java @@ -0,0 +1,71 @@ +package org.jclouds.savvis.vpdc.domain.vapp; + +import java.util.Set; + +import com.google.common.collect.ImmutableSet; + +/** + * The NetworkSection element shall list all logical networks used in the OVF package. + * + * @author Adrian Cole + */ +public class NetworkSection { + private final String info; + private final Set networks; + + public NetworkSection(String info, Iterable networks) { + this.info = info; + this.networks = ImmutableSet. copyOf(networks); + } + + public String getInfo() { + return info; + } + + /** + * All networks referred to from Connection elements in all {@link VirtualHardwareSection} + * elements shall be defined in the NetworkSection. + * + * @return + */ + public Set getNetworks() { + return networks; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((info == null) ? 0 : info.hashCode()); + result = prime * result + ((networks == null) ? 0 : networks.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NetworkSection other = (NetworkSection) obj; + if (info == null) { + if (other.info != null) + return false; + } else if (!info.equals(other.info)) + return false; + if (networks == null) { + if (other.networks != null) + return false; + } else if (!networks.equals(other.networks)) + return false; + return true; + } + + @Override + public String toString() { + return "[info=" + info + ", networks=" + networks + "]"; + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java new file mode 100644 index 0000000000..fed2ed8f91 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClient.java @@ -0,0 +1,110 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.features; + +import javax.annotation.Nullable; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.Org; +import org.jclouds.savvis.vpdc.domain.Task; +import org.jclouds.savvis.vpdc.domain.VApp; +import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie; +import org.jclouds.savvis.vpdc.functions.DefaultOrgIfNull; +import org.jclouds.savvis.vpdc.xml.NetworkHandler; +import org.jclouds.savvis.vpdc.xml.OrgHandler; +import org.jclouds.savvis.vpdc.xml.TaskHandler; +import org.jclouds.savvis.vpdc.xml.VAppHandler; +import org.jclouds.savvis.vpdc.xml.VDCHandler; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to Symphony VPDC resources via their REST API. + *

+ * + * @see + * @author Adrian Cole + */ +@RequestFilters(SetVCloudTokenCookie.class) +@Path("v{jclouds.api-version}") +public interface BrowsingAsyncClient { + + /** + * @see BrowsingClient#getOrg + */ + @GET + @XMLResponseParser(OrgHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("org/{billingSiteId}") + ListenableFuture getOrg( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId); + + /** + * @see BrowsingClient#getVDCInOrg + */ + @GET + @XMLResponseParser(VDCHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("org/{billingSiteId}/vdc/{vpdcId}") + ListenableFuture getVDCInOrg( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId); + + /** + * @see BrowsingClient#getNetworkInOrgAndVDC + */ + @GET + @XMLResponseParser(NetworkHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("org/{billingSiteId}/vdc/{vpdcId}/network/{network-tier-name}") + ListenableFuture getNetworkInOrgAndVDC( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, @PathParam("network-tier-name") String networkTierName); + + /** + * @see BrowsingClient#getVAppInOrgAndVDC + */ + @GET + @XMLResponseParser(VAppHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}") + ListenableFuture getVAppInOrgAndVDC( + @PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId, + @PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId); + + /** + * @see BrowsingClient#getTask + */ + @GET + @XMLResponseParser(TaskHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("task/{taskId}") + ListenableFuture getTask(@PathParam("taskId") String taskId); + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java new file mode 100644 index 0000000000..3e7ce324d1 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/features/BrowsingClient.java @@ -0,0 +1,105 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.features; + +import java.util.concurrent.TimeUnit; + +import javax.annotation.Nullable; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.Org; +import org.jclouds.savvis.vpdc.domain.Task; +import org.jclouds.savvis.vpdc.domain.VApp; +import org.jclouds.savvis.vpdc.domain.VDC; + +/** + * Provides access to Symphony VPDC resources via their REST API. + *

+ * + * @see + * @author Adrian Cole + */ +@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) +public interface BrowsingClient { + /** + * Get an organization, which can contain list of vDC entities + * + * @param billingSiteId + * billing site Id, or null for default + * @return organization, or null if not present + */ + Org getOrg(@Nullable String billingSiteId); + + /** + * VDC is a virtual data center ,the API returns a list of VAPPs own by given bill site Id. + * + * @param billingSiteId + * billing site Id, or null for default + * @param vpdcId + * vpdc Id + * @return a list of resource entity and VM configurations, or null if not present + */ + VDC getVDCInOrg(@Nullable String billingSiteId, String vpdcId); + + /** + * Get Network API returns network detail + * + * @param billingSiteId + * billing site Id, or null for default + * @param vpdcId + * vpdc Id + * @param networkTierName + * network tier name + * + * @return network detail if it used any one deployed VM and NetworkConfigSection defines various + * network features such NAT Public IP, Gateway and Netmask, or null if not present + */ + Network getNetworkInOrgAndVDC(String billingSiteId, String vpdcId, String networkTierName); + + /** + * VAPP is a software solution, the API returns details of virtual machine configuration such as + * CPU,RAM Memory and hard drive. The VM State is from the MW Database. + * + * @param billingSiteId + * billing site Id, or null for default + * @param vpdcId + * vpdc Id + * @param vAppId + * vApp ID + * + * @return A virtual application (vApp) is a software solution comprising one or more virtual + * machines, all of which are deployed, managed, and maintained as a unit, or null if not + * present + */ + VApp getVAppInOrgAndVDC(String billingSiteId, String vpdcId, String vAppId); + + /** + * Gets an existing task. + * + * @param taskId + * task id + * @return If the request is successful, caller could get the VApp/VMDK details as specified in + * the result element and if the request is not successful, caller would get empty + * VAPP/VMDK URL and respective validation (error) message. + */ + Task getTask(String taskId); + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java new file mode 100644 index 0000000000..425eafbeca --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookie.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.filters; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.http.HttpException; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.http.utils.ModifyRequest; +import org.jclouds.savvis.vpdc.internal.VCloudToken; + +/** + * Adds the VCloud Token to the request as a cookie + * + * @author Adrian Cole + * + */ +@Singleton +public class SetVCloudTokenCookie implements HttpRequestFilter { + private Provider vcloudTokenProvider; + + @Inject + public SetVCloudTokenCookie(@VCloudToken Provider authTokenProvider) { + this.vcloudTokenProvider = authTokenProvider; + } + + @Override + public HttpRequest filter(HttpRequest request) throws HttpException { + return ModifyRequest.replaceHeader(request, HttpHeaders.COOKIE, "vcloud-token=" + vcloudTokenProvider.get()); + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java new file mode 100644 index 0000000000..b4228c234b --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/DefaultOrgIfNull.java @@ -0,0 +1,48 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.jclouds.savvis.vpdc.internal.Org; + +import com.google.common.base.Function; + +/** + * + * @author Adrian Cole + */ +public class DefaultOrgIfNull implements Function { + + private Provider defaultOrg; + + @Inject + public DefaultOrgIfNull(@Org Provider defaultOrg) { + this.defaultOrg = checkNotNull(defaultOrg, "defaultOrg"); + } + + public String apply(Object from) { + return from == null ? defaultOrg.get() : from.toString(); + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java new file mode 100644 index 0000000000..c2e6d79fbe --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/functions/ParseLoginResponseFromHeaders.java @@ -0,0 +1,76 @@ +package org.jclouds.savvis.vpdc.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.HttpUtils.releasePayload; + +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.internal.VCloudSession; +import org.jclouds.savvis.vpdc.internal.VCloudToken; +import org.jclouds.savvis.vpdc.xml.OrgListHandler; + +import com.google.common.base.Function; + +/** + * This parses {@link VCloudSession} from HTTP headers. + * + * @author Adrian Cole + */ +@Singleton +public class ParseLoginResponseFromHeaders implements Function { + static final Pattern pattern = Pattern.compile("vcloud-token=([^;]+);.*"); + + private final ParseSax.Factory factory; + private final Provider orgHandlerProvider; + + @Inject + private ParseLoginResponseFromHeaders(Factory factory, + Provider orgHandlerProvider) { + this.factory = factory; + this.orgHandlerProvider = orgHandlerProvider; + } + + /** + * parses the http response headers to create a new {@link VCloudSession} object. + */ + public VCloudSession apply(HttpResponse from) { + String cookieHeader = checkNotNull(from.getFirstHeaderOrNull(HttpHeaders.SET_COOKIE), + HttpHeaders.SET_COOKIE); + + final Matcher matcher = pattern.matcher(cookieHeader); + boolean matchFound = matcher.find(); + try { + if (matchFound) { + final Set org = factory.create(orgHandlerProvider.get()).parse( + from.getPayload().getInput()); + + return new VCloudSession() { + @VCloudToken + public String getVCloudToken() { + return matcher.group(1); + } + + public Set getOrgs() { + return org; + } + }; + + } + } finally { + releasePayload(from); + } + throw new HttpResponseException("not found ", null, from); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/SymphonyVPDCErrorHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandler.java similarity index 97% rename from sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/SymphonyVPDCErrorHandler.java rename to sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandler.java index 6a667705cb..b38c2a9f80 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/SymphonyVPDCErrorHandler.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandler.java @@ -42,7 +42,7 @@ import com.google.common.io.Closeables; * */ @Singleton -public class SymphonyVPDCErrorHandler implements HttpErrorHandler { +public class VPDCErrorHandler implements HttpErrorHandler { @Resource protected Logger logger = Logger.NULL; diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java new file mode 100644 index 0000000000..ab24bd9f01 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/LoginAsyncClient.java @@ -0,0 +1,51 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.internal; + +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.savvis.vpdc.domain.internal.VCloudSession; +import org.jclouds.savvis.vpdc.functions.ParseLoginResponseFromHeaders; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Establishes a context with a VCloud endpoint. + *

+ * + * @see + * @author Adrian Cole + */ +@RequestFilters(BasicAuthentication.class) +public interface LoginAsyncClient { + + /** + * This request returns a token to use in subsequent requests. After 30 minutes of inactivity, + * the token expires and you have to request a new token with this call. + */ + @POST + @ResponseParser(ParseLoginResponseFromHeaders.class) + @Path("v{jclouds.api-version}/login") + ListenableFuture login(); +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java new file mode 100644 index 0000000000..87396d0e53 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Network.java @@ -0,0 +1,40 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.internal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Related to a VCloud Network. + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface Network { + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java new file mode 100644 index 0000000000..d8f74351fc --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/Org.java @@ -0,0 +1,40 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.internal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Related to a VCloud express Org. + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface Org { + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/SymphonyVPDCVDC.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VCloudToken.java similarity index 65% rename from sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/SymphonyVPDCVDC.java rename to sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VCloudToken.java index 7c8913dbf5..d90a52a6b1 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/domain/SymphonyVPDCVDC.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VCloudToken.java @@ -17,18 +17,24 @@ * ==================================================================== */ -package org.jclouds.savvis.vpdc.domain; +package org.jclouds.savvis.vpdc.internal; -import org.jclouds.savvis.vpdc.domain.internal.SymphonyVPDCVDCImpl; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.VDC; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; -import com.google.inject.ImplementedBy; +import javax.inject.Qualifier; /** + * A VCloud Session Token + * * @author Adrian Cole + * */ -@ImplementedBy(SymphonyVPDCVDCImpl.class) -public interface SymphonyVPDCVDC extends VDC { - String getOfferingTag(); +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface VCloudToken { + } \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java new file mode 100644 index 0000000000..5f74684ce0 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/internal/VDC.java @@ -0,0 +1,40 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.internal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Related to a VCloud express Catalog. + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface VDC { + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java new file mode 100644 index 0000000000..fd180ef672 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/predicates/TaskSuccess.java @@ -0,0 +1,42 @@ +package org.jclouds.savvis.vpdc.predicates; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.logging.Logger; +import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.savvis.vpdc.domain.Task; + +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * + * Tests to see if a task succeeds. + * + * @author Adrian Cole + */ +@Singleton +public class TaskSuccess implements Predicate { + + private final VPDCClient client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public TaskSuccess(VPDCClient client) { + this.client = client; + } + + public boolean apply(String taskId) { + logger.trace("looking for status on task %s", taskId); + + Task task = client.getBrowsingClient().getTask(taskId); + logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus()); + if (task.getStatus() == Task.Status.ERROR || task.getStatus() == Task.Status.NONE) + throw new RuntimeException("error on task: " + task.getHref() + " error: " + task.getError()); + return task.getStatus() == Task.Status.SUCCESS; + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudConstants.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudConstants.java new file mode 100644 index 0000000000..38874dcc59 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudConstants.java @@ -0,0 +1,41 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.reference; + +/** + * Configuration properties and constants used in VCloud connections. + * + * @author Adrian Cole + */ +public interface VCloudConstants { + public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema"; + + /** + * name of the default network, in the default VDC that your vApp will join. + */ + public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network"; + public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode"; + + public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns"; + public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema"; + + public static final String PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED = "jclouds.vcloud.timeout.task-complete"; + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java new file mode 100644 index 0000000000..99c9b81878 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/reference/VCloudMediaType.java @@ -0,0 +1,207 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.reference; + +import javax.ws.rs.core.MediaType; + +/** + * Resource Types used in VCloud + * + * @see MediaType + */ +public interface VCloudMediaType { + /** + * "application/vnd.vmware.vcloud.error+xml" + */ + public final static String ERROR_XML = "application/vnd.vmware.vcloud.error+xml"; + + /** + * "application/vnd.vmware.vcloud.error+xml" + */ + public final static MediaType ERROR_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.error+xml"); + + /** + * "application/vnd.vmware.vcloud.vcloud+xml" + */ + public final static String VCLOUD_XML = "application/vnd.vmware.vcloud.vcloud+xml"; + + /** + * "application/vnd.vmware.vcloud.vcloud+xml" + */ + public final static MediaType VCLOUD_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vcloud+xml"); + /** + * "application/vnd.vmware.vcloud.orgList+xml" + */ + public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml"; + + /** + * "application/vnd.vmware.vcloud.orgList+xml" + */ + public final static MediaType ORGLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.orgList+xml"); + /** + * "application/vnd.vmware.vcloud.org+xml" + */ + public final static String ORG_XML = "application/vnd.vmware.vcloud.org+xml"; + /** + * "application/vnd.vmware.vcloud.org+xml" + */ + public final static MediaType ORG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.org+xml"); + + /** + * "application/vnd.vmware.vcloud.vdc+xml" + */ + public final static String VDC_XML = "application/vnd.vmware.vcloud.vdc+xml"; + /** + * "application/vnd.vmware.vcloud.vdc+xml" + */ + public final static MediaType VDC_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vdc+xml"); + + /** + * "application/vnd.vmware.vcloud.catalog+xml" + */ + public final static String CATALOG_XML = "application/vnd.vmware.vcloud.catalog+xml"; + /** + * "application/vnd.vmware.vcloud.catalog+xml" + */ + public final static MediaType CATALOG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.catalog+xml"); + + /** + * "application/vnd.vmware.vcloud.tasksList+xml" + */ + public final static String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml"; + /** + * "application/vnd.vmware.vcloud.tasksList+xml" + */ + public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml"); + + /** + * "application/vnd.vmware.vcloud.catalogItem+xml" + */ + public final static String CATALOGITEM_XML = "application/vnd.vmware.vcloud.catalogItem+xml"; + /** + * "application/vnd.vmware.vcloud.catalogItem+xml" + */ + public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.catalogItem+xml"); + /** + * "application/vnd.vmware.vcloud.networkConnectionSection+xml" + */ + public final static String NETWORKCONNECTIONSECTION_XML = "application/vnd.vmware.vcloud.networkConnectionSection+xml"; + /** + * "application/vnd.vmware.vcloud.networkConnectionSection+xml" + */ + public final static MediaType NETWORKCONNECTIONSECTION_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.networkConnectionSection+xml"); + /** + * "application/vnd.vmware.vcloud.virtualHardwareSection+xml" + */ + public final static String VIRTUALHARDWARESECTION_XML = "application/vnd.vmware.vcloud.virtualHardwareSection+xml"; + /** + * "application/vnd.vmware.vcloud.virtualHardwareSection+xml" + */ + public final static MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.virtualHardwareSection+xml"); + /** + * "application/vnd.vmware.vcloud.guestCustomizationSection+xml" + */ + public final static String GUESTCUSTOMIZATIONSECTION_XML = "application/vnd.vmware.vcloud.guestCustomizationSection+xml"; + /** + * "application/vnd.vmware.vcloud.guestCustomizationSection+xml" + */ + public final static MediaType GUESTCUSTOMIZATIONSECTION_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.guestCustomizationSection+xml"); + + /** + * "application/vnd.vmware.vcloud.networkSection+xml" + */ + public final static String NETWORKSECTION_XML = "application/vnd.vmware.vcloud.networkSection+xml"; + /** + * "application/vnd.vmware.vcloud.networkSection+xml" + */ + public final static MediaType NETWORKSECTION_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.networkSection+xml"); + + /** + * "application/vnd.vmware.vcloud.task+xml" + */ + public final static String TASK_XML = "application/vnd.vmware.vcloud.task+xml"; + /** + * "application/vnd.vmware.vcloud.task+xml" + */ + public final static MediaType TASK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.task+xml"); + + /** + * "application/vnd.vmware.vcloud.undeployVAppParams+xml" + */ + public final static String UNDEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.undeployVAppParams+xml"; + /** + * "application/vnd.vmware.vcloud.undeployVAppParams+xml" + */ + public final static MediaType UNDEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.undeployVAppParams+xml"); + + /** + * "application/vnd.vmware.vcloud.deployVAppParams+xml" + */ + public final static String DEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.deployVAppParams+xml"; + /** + * "application/vnd.vmware.vcloud.deployVAppParams+xml" + */ + public final static MediaType DEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.deployVAppParams+xml"); + + /** + * "application/vnd.vmware.vcloud.vApp+xml" + */ + public final static String VAPP_XML = "application/vnd.vmware.vcloud.vApp+xml"; + /** + * "application/vnd.vmware.vcloud.vApp+xml" + */ + public final static MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml"); + + /** + * "application/vnd.vmware.vcloud.vm+xml" + */ + public final static String VM_XML = "application/vnd.vmware.vcloud.vm+xml"; + /** + * "application/vnd.vmware.vcloud.vm+xml" + */ + public final static MediaType VM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vm+xml"); + + /** + * "application/vnd.vmware.vcloud.vAppTemplate+xml" + */ + public final static String VAPPTEMPLATE_XML = "application/vnd.vmware.vcloud.vAppTemplate+xml"; + /** + * "application/vnd.vmware.vcloud.vAppTemplate+xml" + */ + public final static MediaType VAPPTEMPLATE_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.vAppTemplate+xml"); + + /** + * "application/vnd.vmware.vcloud.network+xml" + */ + public final static String NETWORK_XML = "application/vnd.vmware.vcloud.network+xml"; + /** + * "application/vnd.vmware.vcloud.network+xml" + */ + public final static MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml"); + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java new file mode 100644 index 0000000000..3558729a60 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/util/Utils.java @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.util; + +import java.net.URI; +import java.util.Map; + +import org.jclouds.savvis.vpdc.domain.Link; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.xml.sax.Attributes; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; + +/** + * + * @author Adrian Cole + */ +public class Utils { + + public static Resource newResource(Map attributes, String defaultType) { + String uri = attributes.get("href"); + String type = attributes.get("type"); + // savvis org has null href + String id = null; + URI href = null; + if (uri != null) { + href = URI.create(uri); + id = uri.substring(uri.lastIndexOf('/') + 1); + } + return (attributes.containsKey("rel")) ? new Link(id, attributes.get("name"), type != null ? type : defaultType, + href, attributes.get("rel")) : new Resource(id, attributes.get("name"), type != null ? type : defaultType, + href); + } + + public static Map cleanseAttributes(Attributes in) { + Builder attrs = ImmutableMap. builder(); + for (int i = 0; i < in.getLength(); i++) { + String name = in.getQName(i); + if (name.indexOf(':') != -1) + name = name.substring(name.indexOf(':') + 1); + attrs.put(name, in.getValue(i)); + } + return attrs.build(); + } + + public static String currentOrNull(StringBuilder currentText) { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } + + public static Resource newResource(Map attributes) { + return newResource(attributes, null); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java new file mode 100644 index 0000000000..ef176aa529 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkHandler.java @@ -0,0 +1,80 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; +import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull; +import static org.jclouds.savvis.vpdc.util.Utils.newResource; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +public class NetworkHandler extends ParseSax.HandlerWithResult { + + protected StringBuilder currentText = new StringBuilder(); + + protected Network.Builder builder = Network.builder(); + + public Network getResult() { + try { + return builder.build(); + } finally { + builder = Network.builder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + if (qName.endsWith("Network")) { + // savvis doesn't add href in the header for some reason + if (!attributes.containsKey("href") && getRequest() != null) + attributes = ImmutableMap. builder().putAll(attributes) + .put("href", getRequest().getEndpoint().toASCIIString()).build(); + Resource org = newResource(attributes); + builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref()); + } else if (qName.endsWith("NatRule")) { + builder.internalToExternalNATRule(attributes.get("internalIP"), attributes.get("externalIP")); + } + } + + public void endElement(String uri, String name, String qName) { + if (qName.endsWith("Gateway")) { + builder.gateway(currentOrNull(currentText)); + } else if (qName.endsWith("Netmask")) { + builder.netmask(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkSectionHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkSectionHandler.java new file mode 100644 index 0000000000..eb05aec977 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/NetworkSectionHandler.java @@ -0,0 +1,58 @@ +package org.jclouds.savvis.vpdc.xml; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.vapp.Network; +import org.jclouds.savvis.vpdc.domain.vapp.NetworkSection; +import org.jclouds.savvis.vpdc.util.Utils; +import org.xml.sax.Attributes; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * @author Adrian Cole + */ +public class NetworkSectionHandler extends ParseSax.HandlerWithResult { + protected StringBuilder currentText = new StringBuilder(); + + protected String info; + protected String name; + protected String description; + + protected Builder networks = ImmutableSet. builder(); + + public NetworkSection getResult() { + try { + return new NetworkSection(info, networks.build()); + } finally { + this.info = null; + this.networks = ImmutableSet. builder(); + } + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = Utils.cleanseAttributes(attrs); + if (qName.endsWith("Network")) { + name = attributes.get("name"); + } + } + + @Override + public void endElement(String uri, String localName, String qName) { + if (qName.endsWith("Info")) { + this.info = Utils.currentOrNull(currentText); + } else if (qName.endsWith("Description")) { + this.description = Utils.currentOrNull(currentText); + } else if (qName.endsWith("Network")) { + this.networks.add(new Network(name, description)); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java new file mode 100644 index 0000000000..20b847f872 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgHandler.java @@ -0,0 +1,83 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; +import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull; +import static org.jclouds.savvis.vpdc.util.Utils.newResource; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.Link; +import org.jclouds.savvis.vpdc.domain.Org; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +public class OrgHandler extends ParseSax.HandlerWithResult { + + protected StringBuilder currentText = new StringBuilder(); + + protected Org.Builder builder = Org.builder(); + + public Org getResult() { + try { + return builder.build(); + } finally { + builder = Org.builder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + if (qName.endsWith("Org")) { + // savvis doesn't add href in the header for some reason + if (!attributes.containsKey("href") && getRequest() != null) + attributes = ImmutableMap. builder().putAll(attributes) + .put("href", getRequest().getEndpoint().toASCIIString()).build(); + Resource org = newResource(attributes); + builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref()); + } else if (qName.endsWith("Link")) { + Link link = Link.class.cast(newResource(attributes)); + if ("down".equals(link.getRel())) + builder.vDC(link); + else + builder.image(link); + } + } + + public void endElement(String uri, String name, String qName) { + if (qName.endsWith("Description")) { + builder.description(currentOrNull(currentText)); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java new file mode 100644 index 0000000000..71730f6333 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/OrgListHandler.java @@ -0,0 +1,39 @@ +package org.jclouds.savvis.vpdc.xml; + +import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; +import static org.jclouds.savvis.vpdc.util.Utils.newResource; + +import java.util.Map; +import java.util.Set; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * @author Adrian Cole + */ +public class OrgListHandler extends ParseSax.HandlerWithResult> { + + private Builder org = ImmutableSet. builder(); + + public Set getResult() { + try { + return org.build(); + } finally { + org = ImmutableSet. builder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + if (qName.endsWith("Org")) { + org.add(newResource(attributes)); + } + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandler.java new file mode 100644 index 0000000000..112445d639 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandler.java @@ -0,0 +1,59 @@ +package org.jclouds.savvis.vpdc.xml; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.ResourceAllocation; +import org.jclouds.savvis.vpdc.util.Utils; +import org.xml.sax.Attributes; + +/** + * @author Adrian Cole + */ +public class ResourceAllocationHandler extends ParseSax.HandlerWithResult { + protected StringBuilder currentText = new StringBuilder(); + + protected ResourceAllocation.Builder builder = ResourceAllocation.builder(); + + public ResourceAllocation getResult() { + try { + return builder.build(); + } finally { + builder = ResourceAllocation.builder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) { + } + + @Override + public void endElement(String uri, String localName, String qName) { + String current = Utils.currentOrNull(currentText); + if (current != null) { + if (qName.endsWith("AllocationUnits")) { + builder.allocationUnits(current); + } else if (qName.endsWith("Description")) { + builder.description(current); + } else if (qName.endsWith("ElementName")) { + builder.name(current); + } else if (qName.endsWith("InstanceID")) { + builder.id(Integer.parseInt(current)); + } else if (qName.endsWith("ResourceType")) { + builder.type(ResourceAllocation.Type.fromValue(current)); + } else if (qName.endsWith("VirtualQuantity")) { + builder.virtualQuantity(Long.parseLong(current)); + } else if (qName.endsWith("Caption")) { + builder.caption(current); + } else if (qName.endsWith("Connection")) { + builder.connection(current); + } else if (qName.endsWith("HostResource")) { + builder.hostResource(current); + } + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCNetworkHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCNetworkHandler.java deleted file mode 100644 index ce31f2f95f..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCNetworkHandler.java +++ /dev/null @@ -1,154 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.xml; - -import static org.jclouds.vcloud.util.Utils.cleanseAttributes; -import static org.jclouds.vcloud.util.Utils.newReferenceType; - -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; - -import org.jclouds.http.functions.ParseSax; -import org.jclouds.logging.Logger; -import org.jclouds.savvis.vpdc.domain.SymphonyVPDCNetwork; -import org.jclouds.savvis.vpdc.domain.internal.SymphonyVPDCNetworkImpl; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.network.FenceMode; -import org.jclouds.vcloud.domain.network.firewall.FirewallPolicy; -import org.jclouds.vcloud.domain.network.firewall.FirewallRule; -import org.jclouds.vcloud.domain.network.nat.NatProtocol; -import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -import com.google.common.collect.Sets; - -/** - * @author Kedar Dave - */ -public class SymphonyVPDCNetworkHandler extends ParseSax.HandlerWithResult{ - - @Resource - protected Logger logger = Logger.NULL; - - private ReferenceType ips; - private ReferenceType extension; - - protected StringBuilder currentText = new StringBuilder(); - - protected ReferenceType network; - - protected String description; - - protected Set dnsServers = Sets.newLinkedHashSet(); - protected String gateway; - protected String netmask; - protected Set fenceModes = Sets.newLinkedHashSet(); - protected Boolean dhcp; - protected Set natRules = Sets.newLinkedHashSet(); - protected Set firewallRules = Sets.newLinkedHashSet(); - - protected String externalIP; - protected Integer externalPort; - protected String internalIP; - protected Integer internalPort; - - protected FirewallPolicy policy; - protected String sourceIP; - protected int sourcePort; - - public SymphonyVPDCNetwork getResult() { - return new SymphonyVPDCNetworkImpl(network.getName(), network.getType(), network.getHref(), description, - dnsServers, gateway, netmask, fenceModes, dhcp, natRules, firewallRules); - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { - Map attributes = cleanseAttributes(attrs); - if (qName.endsWith("Network")) { - network = newReferenceType(attributes); - } else if (qName.endsWith("Link")) { - if ("IP Addresses".equals(attributes.get("name"))) { - ips = newReferenceType(attributes); - } else if ("down".equals(attributes.get("rel"))) { - extension = newReferenceType(attributes); - } - } - } - - public void endElement(String uri, String name, String qName) { - if (qName.equals("Description")) { - description = currentOrNull(); - } else if (qName.equals("Dns")) { - dnsServers.add(currentOrNull()); - } else if (qName.equals("Gateway")) { - gateway = currentOrNull(); - } else if (qName.equals("Netmask")) { - netmask = currentOrNull(); - } else if (qName.equals("FenceMode")) { - try { - fenceModes.add(FenceMode.fromValue(currentOrNull())); - } catch (IllegalArgumentException e) { - fenceModes.add(FenceMode.BRIDGED); - } - } else if (qName.equals("Dhcp")) { - dhcp = new Boolean(currentOrNull()); - } else if (qName.equals("NatRule")) { - natRules.add(new PortForwardingRule(externalIP, externalPort, internalIP, internalPort, NatProtocol.TCP_UDP)); - externalIP = null; - externalPort = null; - internalIP = null; - internalPort = null; - } else if (qName.equals("ExternalIP")) { - externalIP = currentOrNull(); - } else if (qName.equals("ExternalPort")) { - externalPort = Integer.parseInt(currentOrNull()); - } else if (qName.equals("InternalIP")) { - internalIP = currentOrNull(); - } else if (qName.equals("InternalPort")) { - internalPort = Integer.parseInt(currentOrNull()); - } else if (qName.equals("FirewallRule")) { - firewallRules.add(new FirewallRule(true, null, policy, null, sourcePort, sourceIP)); - policy = null; - sourceIP = null; - sourcePort = -1; - } else if (qName.equals("Policy")) { - policy = FirewallPolicy.fromValue(currentOrNull()); - } else if (qName.equals("SourceIp")) { - sourceIP = currentOrNull(); - } else if (qName.equals("SourcePort")) { - sourcePort = Integer.parseInt(currentOrNull()); - } - - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } - - protected String currentOrNull() { - String returnVal = currentText.toString().trim(); - return returnVal.equals("") ? null : returnVal; - } - -} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVAppHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVAppHandler.java deleted file mode 100644 index 5e56a0ccc5..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVAppHandler.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.xml; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.vcloud.util.Utils.cleanseAttributes; -import static org.jclouds.vcloud.util.Utils.newReferenceType; - -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; - -import org.jclouds.http.functions.ParseSax; -import org.jclouds.logging.Logger; -import org.jclouds.vcloud.VCloudExpressMediaType; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.VCloudExpressVApp; -import org.jclouds.vcloud.domain.internal.VCloudExpressVAppImpl; -import org.jclouds.vcloud.domain.ovf.ResourceAllocation; -import org.jclouds.vcloud.domain.ovf.System; -import org.jclouds.vcloud.xml.ovf.ResourceAllocationHandler; -import org.jclouds.vcloud.xml.ovf.SystemHandler; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Sets; - -/** - * @author Kedar Dave - */ -public class SymphonyVPDCVAppHandler extends ParseSax.HandlerWithResult { - private final String apiVersion; - private final SystemHandler systemHandler; - private final ResourceAllocationHandler allocationHandler; - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public SymphonyVPDCVAppHandler(@Named(PROPERTY_API_VERSION) String apiVersion, SystemHandler systemHandler, - ResourceAllocationHandler allocationHandler) { - this.apiVersion = apiVersion; - this.systemHandler = systemHandler; - this.allocationHandler = allocationHandler; - } - - protected System system; - protected Set allocations = Sets.newLinkedHashSet(); - protected Status status; - protected final ListMultimap networkToAddresses = ArrayListMultimap.create(); - protected StringBuilder currentText = new StringBuilder(); - protected String operatingSystemDescription; - protected boolean inOs; - protected String networkName; - protected String name; - protected Integer osType; - protected URI location; - protected Long size; - protected ReferenceType vDC; - - public VCloudExpressVApp getResult() { - return new VCloudExpressVAppImpl(name, location, status, size, vDC, networkToAddresses, osType, - operatingSystemDescription, system, allocations); - } - - public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { - Map attributes = cleanseAttributes(attrs); - if (qName.endsWith("VApp")) { - ReferenceType resource = newReferenceType(attributes); - name = resource.getName(); - location = resource.getHref(); - String statusString = attributes.get("status"); - if (apiVersion.indexOf("0.8") != -1 && "2".equals(statusString)) - status = Status.OFF; - else - status = Status.fromValue(statusString); - if (attributes.containsKey("size")) - size = new Long(attributes.get("size")); - } else if (qName.equals("Link")) { // type should never be missing - if (attributes.containsKey("type") && attributes.get("type").equals(VCloudExpressMediaType.VDC_XML)) { - vDC = newReferenceType(attributes); - } - } else if (qName.endsWith("OperatingSystemSection")) { - inOs = true; - if (attributes.containsKey("id")) - osType = Integer.parseInt(attributes.get("id")); - } else if (qName.endsWith("NetworkConnection")) { - networkName = attributes.get("Network"); - } else { - systemHandler.startElement(uri, localName, qName, attrs); - allocationHandler.startElement(uri, localName, qName, attrs); - } - - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - if (qName.endsWith("OperatingSystemSection")) { - inOs = false; - } else if (inOs && qName.endsWith("Description")) { - operatingSystemDescription = currentText.toString().trim(); - } else if (qName.endsWith("IpAddress")) { - networkToAddresses.put(networkName, currentText.toString().trim()); - } else if (qName.equals("System")) { - systemHandler.endElement(uri, localName, qName); - system = systemHandler.getResult(); - } else if (qName.equals("Item")) { - allocationHandler.endElement(uri, localName, qName); - allocations.add(allocationHandler.getResult()); - } else { - systemHandler.endElement(uri, localName, qName); - allocationHandler.endElement(uri, localName, qName); - } - currentText = new StringBuilder(); - } - - @Override - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - systemHandler.characters(ch, start, length); - allocationHandler.characters(ch, start, length); - } - -} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandler.java deleted file mode 100644 index b1295f29c6..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.xml; - -import javax.inject.Inject; - -import org.jclouds.savvis.vpdc.domain.SymphonyVPDCVDC; -import org.jclouds.savvis.vpdc.domain.internal.SymphonyVPDCVDCImpl; -import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.xml.TaskHandler; -import org.jclouds.vcloud.xml.VDCHandler; - -/** - * @author Adrian Cole - */ -public class SymphonyVPDCVDCHandler extends VDCHandler { - - @Inject - public SymphonyVPDCVDCHandler(TaskHandler taskHandler) { - super(taskHandler); - } - - private String offeringTag; - - public SymphonyVPDCVDC getResult() { - VDC vDC = super.getResult(); - return new SymphonyVPDCVDCImpl(vDC.getName(), vDC.getType(), vDC.getHref(), status, org, description, tasks, - allocationModel, storageCapacity, cpuCapacity, memoryCapacity, resourceEntities, availableNetworks, - nicQuota, networkQuota, vmQuota, isEnabled, offeringTag); - } - - @Override - public void endElement(String uri, String name, String qName) { - if (qName.endsWith("OfferingTag")) { - this.offeringTag = currentOrNull(); - } - super.endElement(uri, name, qName); - - } - -} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java new file mode 100644 index 0000000000..49f8e44743 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TaskHandler.java @@ -0,0 +1,106 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; +import static org.jclouds.savvis.vpdc.util.Utils.newResource; + +import java.util.Date; +import java.util.Map; + +import javax.inject.Inject; + +import org.jclouds.date.DateService; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.logging.Logger; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.Task; +import org.jclouds.savvis.vpdc.domain.TaskError; +import org.jclouds.savvis.vpdc.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * @author Adrian Cole + */ +public class TaskHandler extends ParseSax.HandlerWithResult { + @javax.annotation.Resource + protected Logger logger = Logger.NULL; + + protected final DateService dateService; + + private Task.Builder builder = Task.builder(); + + @Inject + public TaskHandler(DateService dateService) { + this.dateService = dateService; + } + + public Task getResult() { + try { + return builder.build(); + } finally { + builder = Task.builder(); + } + + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + if (qName.endsWith("Task")) { + Resource task = newResource(attributes); + builder.id(task.getId()); + builder.type(task.getType()); + builder.href(task.getHref()); + if (attributes.containsKey("startTime")) + builder.startTime(parseDate(attributes.get("startTime"))); + if (attributes.containsKey("endTime")) + builder.endTime(parseDate(attributes.get("endTime"))); + builder.status(Task.Status.fromValue(attributes.get("status"))); + } else if (qName.endsWith("Owner")) { + builder.owner(Utils.newResource(attributes)); + } else if (qName.endsWith("Result")) { + builder.result(Utils.newResource(attributes)); + } else if (qName.endsWith("Error")) { + builder.error(new TaskError(attributes.get("message"), Integer.parseInt(attributes.get("majorErrorCode")), + Integer.parseInt(attributes.get("minorErrorCode")), attributes.get("vendorSpecificErrorCode"))); + } + + } + + private Date parseDate(String toParse) { + try { + return dateService.iso8601DateParse(toParse); + } catch (RuntimeException e) { + logger.error(e, "error parsing date, %s", toParse); + } + return null; + } + + @Override + public void endElement(String uri, String localName, String qName) { + } + + @Override + public void characters(char ch[], int start, int length) { + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java new file mode 100644 index 0000000000..3c5a22044a --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/TasksListHandler.java @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import java.util.Set; + +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.Task; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * @author Adrian Cole + */ +public class TasksListHandler extends ParseSax.HandlerWithResult> { + + private Builder tasks = ImmutableSet. builder(); + private final TaskHandler taskHandler; + + @Inject + public TasksListHandler(TaskHandler taskHandler) { + this.taskHandler = taskHandler; + } + + public Set getResult() { + try { + return tasks.build(); + } finally { + tasks = ImmutableSet. builder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + taskHandler.startElement(uri, localName, qName, attrs); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + taskHandler.endElement(uri, localName, qName); + if (qName.equals("Task")) { + this.tasks.add(taskHandler.getResult()); + } + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VAppHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VAppHandler.java new file mode 100644 index 0000000000..b78ba99f80 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VAppHandler.java @@ -0,0 +1,111 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.jclouds.savvis.vpdc.util.Utils.newResource; + +import java.util.Map; + +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.VApp; +import org.jclouds.savvis.vpdc.util.Utils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Kedar Dave + */ +public class VAppHandler extends ParseSax.HandlerWithResult { + protected StringBuilder currentText = new StringBuilder(); + private final NetworkSectionHandler networkSectionHandler; + private final ResourceAllocationHandler allocationHandler; + + @Inject + public VAppHandler(NetworkSectionHandler networkSectionHandler, ResourceAllocationHandler allocationHandler) { + this.networkSectionHandler = networkSectionHandler; + this.allocationHandler = allocationHandler; + } + + private VApp.Builder builder = VApp.builder(); + protected boolean inOs; + + public VApp getResult() { + try { + return builder.build(); + } finally { + builder = VApp.builder(); + } + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = Utils.cleanseAttributes(attrs); + if (qName.endsWith("VApp")) { + // savvis doesn't add href in the header for some reason + if (!attributes.containsKey("href") && getRequest() != null) + attributes = ImmutableMap. builder().putAll(attributes) + .put("href", getRequest().getEndpoint().toASCIIString()).build(); + Resource vApp = newResource(attributes); + builder.name(vApp.getName()).type(vApp.getType()).id(vApp.getId()).href(vApp.getHref()); + builder.status(VApp.Status.fromValue(attributes.get("status"))); + } else if (qName.endsWith("OperatingSystemSection")) { + inOs = true; + if (attributes.containsKey("id")) + builder.osType(Integer.parseInt(attributes.get("id"))); + } else { + networkSectionHandler.startElement(uri, localName, qName, attrs); + allocationHandler.startElement(uri, localName, qName, attrs); + } + + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (qName.endsWith("OperatingSystemSection")) { + inOs = false; + } else if (inOs && qName.endsWith("Description")) { + builder.osDescripton(Utils.currentOrNull(currentText)); + } else if (qName.endsWith("IpAddress")) { + builder.ipAddress(Utils.currentOrNull(currentText)); + } else if (qName.endsWith("NetworkSection")) { + networkSectionHandler.endElement(uri, localName, qName); + builder.networkSection(networkSectionHandler.getResult()); + } else if (qName.endsWith("Item")) { + allocationHandler.endElement(uri, localName, qName); + builder.resourceAllocation(allocationHandler.getResult()); + } else { + networkSectionHandler.endElement(uri, localName, qName); + allocationHandler.endElement(uri, localName, qName); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + networkSectionHandler.characters(ch, start, length); + allocationHandler.characters(ch, start, length); + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java new file mode 100644 index 0000000000..e06f161a55 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/main/java/org/jclouds/savvis/vpdc/xml/VDCHandler.java @@ -0,0 +1,83 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; +import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull; +import static org.jclouds.savvis.vpdc.util.Utils.newResource; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.domain.VDC.Status; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +public class VDCHandler extends ParseSax.HandlerWithResult { + + protected StringBuilder currentText = new StringBuilder(); + + protected VDC.Builder builder = VDC.builder(); + + public VDC getResult() { + try { + return builder.build(); + } finally { + builder = VDC.builder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + if (qName.endsWith("Vdc")) { + // savvis doesn't add href in the header for some reason + if (!attributes.containsKey("href") && getRequest() != null) + attributes = ImmutableMap. builder().putAll(attributes) + .put("href", getRequest().getEndpoint().toASCIIString()).build(); + Resource vDC = newResource(attributes); + builder.name(vDC.getName()).type(vDC.getType()).id(vDC.getId()).href(vDC.getHref()); + } else if (qName.endsWith("Network")) { + builder.availableNetwork(newResource(attributes)); + } else if (qName.endsWith("ResourceEntity")) { + builder.resourceEntity(newResource(attributes)); + } + } + + public void endElement(String uri, String name, String qName) { + if (qName.endsWith("Description")) { + builder.description(currentOrNull(currentText)); + } else if (qName.endsWith("OfferingTag")) { + builder.status(Status.fromValue(currentOrNull(currentText))); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClientTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClientTest.java deleted file mode 100644 index 3a7b8a5e2e..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCAsyncClientTest.java +++ /dev/null @@ -1,903 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc; - -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_IDENTITY; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.URI; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Properties; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.RequiresHttp; -import org.jclouds.http.functions.ParseSax; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.rest.RestContextSpec; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.savvis.vpdc.config.SymphonyVPDCRestClientModule; -import org.jclouds.savvis.vpdc.xml.SymphonyVPDCNetworkHandler; -import org.jclouds.savvis.vpdc.xml.SymphonyVPDCVAppHandler; -import org.jclouds.savvis.vpdc.xml.SymphonyVPDCVDCHandler; -import org.jclouds.util.Strings2; -import org.jclouds.vcloud.CommonVCloudClient; -import org.jclouds.vcloud.VCloudExpressLoginAsyncClient; -import org.jclouds.vcloud.VCloudExpressMediaType; -import org.jclouds.vcloud.VCloudVersionsAsyncClient; -import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.VCloudSession; -import org.jclouds.vcloud.domain.internal.CatalogImpl; -import org.jclouds.vcloud.domain.internal.CatalogItemImpl; -import org.jclouds.vcloud.domain.internal.OrgImpl; -import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; -import org.jclouds.vcloud.domain.internal.VDCImpl; -import org.jclouds.vcloud.domain.network.FenceMode; -import org.jclouds.vcloud.domain.network.NetworkConfig; -import org.jclouds.vcloud.filters.SetVCloudTokenCookie; -import org.jclouds.vcloud.options.CloneVAppOptions; -import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; -import org.jclouds.vcloud.xml.CatalogHandler; -import org.jclouds.vcloud.xml.CatalogItemHandler; -import org.jclouds.vcloud.xml.OrgHandler; -import org.jclouds.vcloud.xml.TaskHandler; -import org.jclouds.vcloud.xml.TasksListHandler; -import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; -import org.jclouds.vcloud.xml.VCloudExpressVAppTemplateHandler; -import org.testng.annotations.Test; - -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; - -/** - * Tests annotation parsing of {@code SymphonyVPDCAsyncClient} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class SymphonyVPDCAsyncClientTest extends RestClientTest { - public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"), - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vAppTemplate/3"), "my-vapp"); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals( - request, - Strings2.toStringAndClose(getClass().getResourceAsStream("/express/newvapp-hosting.xml")).replace( - "vcloud.safesecureweb.com/api", "api.sandbox.symphonyVPDC.savvis.net/rest/api"), - "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, VCloudExpressVAppHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, - IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - HttpRequest request = processor.createRequest( - method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"), - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vAppTemplate/3"), - "my-vapp", - processorCount(1) - .memory(512) - .disk(1024) - .addNetworkConfig( - new NetworkConfig(null, URI.create("https://vcloud.safesecureweb.com/network/1990"), - FenceMode.BRIDGED))); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, - Strings2.toStringAndClose(getClass().getResourceAsStream("/express/newvapp-hostingcpumemdisk.xml")) - .replace("vcloud.safesecureweb.com/api", "api.sandbox.symphonyVPDC.savvis.net/rest/api"), - "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, VCloudExpressVAppHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException, - IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - processor.createRequest( - method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"), - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"), - "CentOS 01", - processorCount(1) - .memory(512) - .disk(1024) - .addNetworkConfig( - new NetworkConfig("aloha", URI - .create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"), null))); - } - - public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"), - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vapp/4181"), "my-vapp"); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals( - request, - Strings2.toStringAndClose(getClass().getResourceAsStream("/express/cloneVApp-default.xml")).replace( - "vcloud.safesecureweb.com/api", "api.sandbox.symphonyVPDC.savvis.net/rest/api"), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"), - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vapp/201"), "new-linux-server", - new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/express/cloneVApp.xml")) - .replace("vcloud.safesecureweb.com/api", "api.sandbox.symphonyVPDC.savvis.net/rest/api"), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getOrg", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org/1")); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, OrgHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testFindOrgNamed() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findOrgNamed", String.class); - HttpRequest request = processor.createRequest(method, "org"); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, OrgHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getCatalog", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalog/1")); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalog/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, CatalogHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCatalogInOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findCatalogInOrgNamed", String.class, String.class); - HttpRequest request = processor.createRequest(method, "org", "catalog"); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalog/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, CatalogHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getNetwork", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/network/2")); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/network/2 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SymphonyVPDCNetworkHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getCatalogItem", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalogItem/2")); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalogItem/2 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, - String.class, String.class); - HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalogItem/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class, - String.class, String.class); - HttpRequest request = processor.createRequest(method, "org", "catalog", "template"); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vAppTemplate/2 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, VCloudExpressVAppTemplateHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getVAppTemplate", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vAppTemplate/2")); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vAppTemplate/2 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, VCloudExpressVAppTemplateHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testFindVDCInOrgNamed() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); - HttpRequest request = processor.createRequest(method, "org", "vdc"); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SymphonyVPDCVDCHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - @Test(expectedExceptions = NoSuchElementException.class) - public void testFindVDCInOrgNamedBadVDC() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); - processor.createRequest(method, "org", "vdc1"); - } - - @Test(expectedExceptions = NoSuchElementException.class) - public void testFindVDCInOrgNamedBadOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); - processor.createRequest(method, "org1", "vdc"); - } - - public void testFindVDCInOrgNamedNullOrg() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); - HttpRequest request = processor.createRequest(method, null, "vdc"); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SymphonyVPDCVDCHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testFindVDCInOrgNamedNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); - HttpRequest request = processor.createRequest(method, null, null); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SymphonyVPDCVDCHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getVDC", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1")); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SymphonyVPDCVDCHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getTasksList", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/tasksList/1")); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/tasksList/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TasksListHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testFindTasksListInOrgNamed() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class); - HttpRequest request = processor.createRequest(method, "org"); - - assertRequestLineEquals(request, - "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/tasksList/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TasksListHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("deployVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1/action/deploy HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testGet() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, SymphonyVPDCVAppHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("undeployVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1/action/undeploy HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testDelete() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("deleteVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "DELETE https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testPowerOnVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("powerOnVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1/power/action/powerOn HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testPowerOffVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("powerOffVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1/power/action/powerOff HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testResetVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("resetVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1/power/action/reset HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testSuspendVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("suspendVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1/power/action/suspend HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testShutdownVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("shutdownVApp", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/1/power/action/shutdown HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("getTask", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/task/1")); - - assertRequestLineEquals(request, "GET https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/task/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, TaskHandler.class); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { - Method method = SymphonyVPDCAsyncClient.class.getMethod("cancelTask", URI.class); - HttpRequest request = processor.createRequest(method, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/task/1")); - - assertRequestLineEquals(request, - "POST https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/task/1/action/cancel HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - - @Override - protected void checkFilters(HttpRequest request) { - assertEquals(request.getFilters().size(), 1); - assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); - } - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } - - @Override - protected Module createModule() { - return new SymphonyVPDCRestClientModuleExtension(); - } - - @Override - public RestContextSpec createContextSpec() { - Properties restProperties = new Properties(); - restProperties.setProperty("savvis-symphony-vpdc.contextbuilder", SymphonyVPDCContextBuilder.class.getName()); - restProperties.setProperty("savvis-symphony-vpdc.propertiesbuilder", - SymphonyVPDCPropertiesBuilder.class.getName()); - - Properties overrides = new Properties(); - overrides.setProperty("savvis-symphony-vpdc.endpoint", - "https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8"); - return new RestContextFactory(restProperties).createContextSpec("savvis-symphony-vpdc", "identity", "credential", - overrides); - } - - @RequiresHttp - @ConfiguresRestClient - public static class SymphonyVPDCRestClientModuleExtension extends SymphonyVPDCRestClientModule { - @Override - protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, - @Named(PROPERTY_API_VERSION) String version) { - return URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/login"); - } - - @Override - protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable orgs) { - return URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org"); - - } - - @Override - protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable orgs) { - return "org"; - } - - @Override - protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) { - return URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalog"); - - } - - @Override - protected Org provideOrg(CommonVCloudClient discovery) { - return null; - } - - @Override - protected Iterable provideOrgs(Supplier cache, @Named(PROPERTY_IDENTITY) String user) { - return null; - } - - @Override - protected URI provideDefaultTasksList(Org org) { - return URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/taskslist"); - } - - @Override - protected URI provideDefaultVDC(Org org, @org.jclouds.vcloud.endpoints.VDC String defaultVDC) { - return URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"); - } - - @Override - protected String provideDefaultVDCName( - @org.jclouds.vcloud.endpoints.VDC Supplier> vDCtoOrgSupplier) { - return "vdc"; - } - - @Override - protected URI provideDefaultNetwork(URI vdc, Injector injector) { - return URI.create("https://vcloud.safesecureweb.com/network/1990"); - } - - @Override - protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final VCloudExpressLoginAsyncClient login) { - return Suppliers. ofInstance(new VCloudSession() { - - @Override - public Map getOrgs() { - return ImmutableMap. of( - "org", - new ReferenceTypeImpl("org", VCloudExpressMediaType.ORG_XML, URI - .create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org/1"))); - } - - @Override - public String getVCloudToken() { - return "token"; - } - - }); - - } - - @Override - protected void configure() { - super.configure(); - bind(OrgMapSupplier.class).to(TestOrgMapSupplier.class); - bind(OrgCatalogSupplier.class).to(TestOrgCatalogSupplier.class); - bind(OrgCatalogItemSupplier.class).to(TestOrgCatalogItemSupplier.class); - } - - protected Supplier>> provideOrgVDCSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) { - - return Suppliers - .>> ofInstance(ImmutableMap.> of( - "org", - - ImmutableMap. of( - "vdc", - new VDCImpl( - "vdc", - null, - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"), - null, - null, - "description", - null, - null, - null, - null, - null, - ImmutableMap. of( - "vapp", - new ReferenceTypeImpl( - "vapp", - "application/vnd.vmware.vcloud.vApp+xml", - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vApp/188849-1")), - "network", - new ReferenceTypeImpl( - "network", - "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdcItem/2"))), - null, 0, 0, 0, false)))); - - } - - @Singleton - public static class TestOrgMapSupplier extends OrgMapSupplier { - @Inject - protected TestOrgMapSupplier() { - super(null, null); - } - - @Override - public Map get() { - return ImmutableMap. of( - "org", - new OrgImpl("org", null, URI - .create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/org/1"), "org", null, - ImmutableMap. of( - "catalog", - new ReferenceTypeImpl("catalog", VCloudExpressMediaType.CATALOG_XML, URI - .create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalog/1"))), - ImmutableMap. of( - "vdc", - new ReferenceTypeImpl("vdc", VCloudExpressMediaType.VDC_XML, URI - .create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vdc/1"))), - ImmutableMap. of(), new ReferenceTypeImpl("tasksList", - VCloudExpressMediaType.TASKSLIST_XML, URI - .create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/tasksList/1")), - ImmutableList. of())); - } - } - - @Singleton - public static class TestOrgCatalogSupplier extends OrgCatalogSupplier { - @Inject - protected TestOrgCatalogSupplier() { - super(null, null); - } - - @Override - public Map> get() { - return ImmutableMap - .> of( - "org", - - ImmutableMap. of( - "catalog", - new CatalogImpl( - "catalog", - "type", - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalog/1"), - null, - "description", - ImmutableMap. of( - "item", - new ReferenceTypeImpl( - "item", - "application/vnd.vmware.vcloud.catalogItem+xml", - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalogItem/1")), - "template", - new ReferenceTypeImpl( - "template", - "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalogItem/2"))), - ImmutableList. of(), true))); - } - } - - @Singleton - public static class TestOrgCatalogItemSupplier extends OrgCatalogItemSupplier { - protected TestOrgCatalogItemSupplier() { - super(null, null); - } - - @Override - public Map>> get() { - return ImmutableMap - .>> of( - "org", - ImmutableMap.> of( - "catalog", - ImmutableMap - . of( - "template", - new CatalogItemImpl( - "template", - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/catalogItem/2"), - "description", - new ReferenceTypeImpl( - "template", - "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI.create("https://api.sandbox.symphonyVPDC.savvis.net/rest/api/v0.8/vAppTemplate/2")), - ImmutableMap. of())))); - - } - } - - } - -} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCClientLiveTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCClientLiveTest.java deleted file mode 100644 index ecd00306e5..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/SymphonyVPDCClientLiveTest.java +++ /dev/null @@ -1,326 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc; - -import static com.google.common.collect.Iterables.find; -import static org.jclouds.vcloud.options.CloneVAppOptions.Builder.deploy; -import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; -import java.util.Properties; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.domain.Credentials; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.net.IPSocket; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.predicates.SocketOpen; -import org.jclouds.rest.RestContextFactory; -import org.jclouds.ssh.SshClient; -import org.jclouds.ssh.SshClient.Factory; -import org.jclouds.ssh.SshException; -import org.jclouds.ssh.jsch.config.JschSshClientModule; -import org.jclouds.vcloud.VCloudExpressClientLiveTest; -import org.jclouds.vcloud.VCloudMediaType; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.Status; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.VCloudExpressVApp; -import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; -import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.domain.ovf.ResourceType; -import org.jclouds.vcloud.options.CloneVAppOptions; -import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; -import org.jclouds.vcloud.predicates.TaskSuccess; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.inject.Injector; -import com.google.inject.Module; - -public class SymphonyVPDCClientLiveTest extends VCloudExpressClientLiveTest { - public SymphonyVPDCClientLiveTest() { - provider = "savvis-symphony-vpdc"; - } - - @BeforeGroups(groups = { "live" }) - @Override - public void setupClient() { - setupCredentials(); - Properties overrides = setupProperties(); - - // TODO remove these lines when this is registered under jclouds-core/rest.properties - Properties restProperties = new Properties(); - restProperties.setProperty("savvis-symphony-vpdc.contextbuilder", SymphonyVPDCContextBuilder.class.getName()); - restProperties.setProperty("savvis-symphony-vpdc.propertiesbuilder", - SymphonyVPDCPropertiesBuilder.class.getName()); - - Injector injector = new RestContextFactory(restProperties).createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector(); - - connection = injector.getInstance(SymphonyVPDCClient.class); - - sshFactory = injector.getInstance(SshClient.Factory.class); - socketTester = new RetryablePredicate(injector.getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make - // it - // longer - // then - // default internet - // service timeout - successTester = new RetryablePredicate(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS); - } - - protected String expectedOs = "Ubuntu Linux (64-bit)"; - protected String itemName = "Ubuntu JeOS 9.10 (64-bit)"; - - protected Factory sshFactory; - private VCloudExpressVApp vApp; - private RetryablePredicate socketTester; - private RetryablePredicate successTester; - private VCloudExpressVApp clone; - private VDC vdc; - public static final String PREFIX = System.getProperty("user.name") + "-savvis"; - - @Test(enabled = true) - public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException, TimeoutException, - IOException { - prepare(); - StringBuffer name = new StringBuffer(); - for (int i = 0; i < 15; i++) - name.append("c"); - String serverName = name.toString();// "adriantest"; - - long hardDisk = 4194304; - - // long hardDisk = 4194304 / 4 * 10; - // String catalogOs = "CentOS 5.3 (64-bit)"; - // String expectedOs = "Red Hat Enterprise Linux 5 (64-bit)"; - - // lookup the datacenter you are deploying into - vdc = connection.findVDCInOrgNamed(null, null); - - ReferenceType vAppTemplateId = Iterables.find(vdc.getResourceEntities().values(), new Predicate() { - - @Override - public boolean apply(ReferenceType arg0) { - return arg0.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML); - } - - }); - - VCloudExpressVAppTemplate vAppTemplate = connection.getVAppTemplate(vAppTemplateId.getHref()); - - assert vAppTemplate != null; - - // create an options object to collect the configuration we want. - InstantiateVAppTemplateOptions instantiateOptions = new InstantiateVAppTemplateOptions(); - - // instantiate, noting vApp returned has minimal details - vApp = connection.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName, - instantiateOptions); - - assertEquals(vApp.getStatus(), Status.RESOLVED); - - Task deployTask = connection.deployVApp(vApp.getHref()); - - // check to see the result of calling deploy twice - deployTask = connection.deployVApp(vApp.getHref()); - assertEquals(deployTask.getHref(), deployTask.getHref()); - - vApp = connection.getVApp(vApp.getHref()); - - assertEquals(vApp.getStatus(), Status.RESOLVED); - - try {// per docs, this is not supported - connection.cancelTask(deployTask.getHref()); - } catch (UnsupportedOperationException e) { - } - - assert successTester.apply(deployTask.getHref()); - System.out.printf("%d: done deploying vApp%n", System.currentTimeMillis()); - - vApp = connection.getVApp(vApp.getHref()); - - ReferenceType vAppResource = connection.findVDCInOrgNamed(null, null).getResourceEntities().get(serverName); - assertEquals(vAppResource.getHref(), vApp.getHref()); - - int processorCount = 1; - long memory = 512; - verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk); - assertEquals(vApp.getStatus(), Status.OFF); - - assert successTester.apply(connection.powerOnVApp(vApp.getHref()).getHref()); - System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis()); - - vApp = connection.getVApp(vApp.getHref()); - assertEquals(vApp.getStatus(), Status.ON); - } - - protected void prepare() { - - } - - @Test(enabled = true, dependsOnMethods = "testInstantiateAndPowerOn") - public void testCloneVApp() throws IOException { - assert successTester.apply(connection.powerOffVApp(vApp.getHref()).getHref()); - System.out.printf("%d: done powering off vApp%n", System.currentTimeMillis()); - - StringBuffer name = new StringBuffer(); - for (int i = 0; i < 15; i++) - name.append("b"); - String newName = name.toString(); - - CloneVAppOptions options = deploy().powerOn().withDescription("The description of " + newName); - - System.out.printf("%d: cloning vApp%n", System.currentTimeMillis()); - Task task = connection.cloneVAppInVDC(vdc.getHref(), vApp.getHref(), newName, options); - - // wait for the task to complete - assert successTester.apply(task.getHref()); - System.out.printf("%d: done cloning vApp%n", System.currentTimeMillis()); - - assert successTester.apply(connection.powerOnVApp(vApp.getHref()).getHref()); - System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis()); - - // refresh task to get the new vApp location - task = connection.getTask(task.getHref()); - - clone = connection.getVApp(task.getOwner().getHref()); - assertEquals(clone.getStatus(), Status.ON); - - assertEquals(clone.getName(), newName); - assertEquals(clone.getNetworkToAddresses().values().size(), 1); - } - - private void loopAndCheckPass(String publicIp) throws IOException { - for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate. - try { - doCheckPass(publicIp); - return; - } catch (SshException e) { - try { - Thread.sleep(10 * 1000); - } catch (InterruptedException e1) { - } - continue; - } - } - } - - @Test(enabled = true, dependsOnMethods = "testCloneVApp") - public void testLifeCycle() throws InterruptedException, ExecutionException, TimeoutException, IOException { - - try {// per docs, this is not supported - connection.undeployVApp(vApp.getHref()); - assert false; - } catch (UnsupportedOperationException e) { - } - - try {// per docs, this is not supported - connection.suspendVApp(vApp.getHref()); - assert false; - } catch (UnsupportedOperationException e) { - } - - assert successTester.apply(connection.resetVApp(vApp.getHref()).getHref()); - - vApp = connection.getVApp(vApp.getHref()); - - assertEquals(vApp.getStatus(), Status.ON); - - // TODO we need to determine whether shutdown is supported before invoking - // it. - // connection.shutdownVApp(vApp.getId()); - // vApp = connection.getVApp(vApp.getId()); - // assertEquals(vApp.getStatus(), VAppStatus.ON); - - assert successTester.apply(connection.powerOffVApp(vApp.getHref()).getHref()); - - vApp = connection.getVApp(vApp.getHref()); - assertEquals(vApp.getStatus(), Status.OFF); - } - - private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs, - int processorCount, long memory, long hardDisk) { - assertEquals(vApp.getName(), serverName); - assertEquals(vApp.getOperatingSystemDescription(), expectedOs); - assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(), - processorCount); - assertEquals( - find(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER)).getVirtualQuantity(), 1); - assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(), memory); - assertEquals(find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity(), - hardDisk); - assertEquals(vApp.getSize().longValue(), - find(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)).getVirtualQuantity()); - } - - private void doCheckPass(String address) throws IOException { - IPSocket socket = new IPSocket(address, 22); - - System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), socket); - assert socketTester.apply(socket); - System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), socket); - - SshClient connection = getConnectionFor(socket); - try { - connection.connect(); - System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), socket); - System.out.println(connection.exec("df -h")); - } finally { - if (connection != null) - connection.disconnect(); - } - } - - protected SshClient getConnectionFor(IPSocket socket) { - // TODO add in the correct login credentials for the vApp template - return sshFactory.create(socket, new Credentials("root", "password")); - } - - @AfterTest - void cleanup() throws InterruptedException, ExecutionException, TimeoutException { - if (vApp != null) { - try { - successTester.apply(connection.powerOffVApp(vApp.getHref()).getHref()); - } catch (Exception e) { - - } - connection.deleteVApp(vApp.getHref()); - } - if (clone != null) { - try { - successTester.apply(connection.powerOffVApp(clone.getHref()).getHref()); - } catch (Exception e) { - - } - connection.deleteVApp(clone.getHref()); - } - - } -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java new file mode 100644 index 0000000000..cfc57520b1 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/VPDCAsyncClientTest.java @@ -0,0 +1,71 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.savvis.vpdc.features.BaseVPDCAsyncClientTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code VPDCAsyncClient} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "VPDCAsyncClientTest") +public class VPDCAsyncClientTest extends BaseVPDCAsyncClientTest { + + private VPDCAsyncClient asyncClient; + private VPDCClient syncClient; + + public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { + assert syncClient.getBrowsingClient() != null; + } + + public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { + assert asyncClient.getBrowsingClient() != null; + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @BeforeClass + @Override + protected void setupFactory() throws IOException { + super.setupFactory(); + asyncClient = injector.getInstance(VPDCAsyncClient.class); + syncClient = injector.getInstance(VPDCClient.class); + } + + @Override + protected void checkFilters(HttpRequest request) { + + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java deleted file mode 100644 index b3ee5db239..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.compute; - -import java.util.Properties; - -import org.jclouds.compute.BaseComputeServiceLiveTest; -import org.jclouds.savvis.vpdc.SymphonyVPDCContextBuilder; -import org.jclouds.savvis.vpdc.SymphonyVPDCPropertiesBuilder; -import org.jclouds.ssh.jsch.config.JschSshClientModule; -import org.testng.annotations.Test; - -/** - * - * - * @author Kedar Dave - */ -@Test(groups = "live", enabled = false, sequential = true) -public class SymphonyVPDCComputeServiceLiveTest extends BaseComputeServiceLiveTest { - public SymphonyVPDCComputeServiceLiveTest() { - provider = "savvis-symphony-vpdc"; - group = "savvis.jclouds"; - } - - @Override - protected Properties setupRestProperties() { - // TODO remove these lines when this is registered under jclouds-core/rest.properties - Properties restProperties = new Properties(); - restProperties.setProperty("savvis-symphony-vpdc.contextbuilder", SymphonyVPDCContextBuilder.class.getName()); - restProperties.setProperty("savvis-symphony-vpdc.propertiesbuilder", - SymphonyVPDCPropertiesBuilder.class.getName()); - return restProperties; - } - - @Override - protected JschSshClientModule getSshModule() { - return new JschSshClientModule(); - } - -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCTemplateBuilderLiveTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCTemplateBuilderLiveTest.java deleted file mode 100644 index 30cd9d297c..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCTemplateBuilderLiveTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.jclouds.savvis.vpdc.compute; - -import static org.jclouds.compute.util.ComputeServiceUtils.getCores; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.domain.os.OsFamilyVersion64Bit; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.savvis.vpdc.SymphonyVPDCContextBuilder; -import org.jclouds.savvis.vpdc.SymphonyVPDCPropertiesBuilder; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "live", enabled = false) -public class SymphonyVPDCTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { - - public SymphonyVPDCTemplateBuilderLiveTest() { - provider = "savvis-symphony-vpdc"; - } - - @Override - @BeforeClass - public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { - setupCredentials(); - // TODO remove these lines when this is registered under jclouds-core/rest.properties - Properties restProperties = new Properties(); - restProperties.setProperty("savvis-symphony-vpdc.contextbuilder", SymphonyVPDCContextBuilder.class.getName()); - restProperties.setProperty("savvis-symphony-vpdc.propertiesbuilder", - SymphonyVPDCPropertiesBuilder.class.getName()); - - context = new ComputeServiceContextFactory(restProperties).createContext(provider, - ImmutableSet. of(new Log4JLoggingModule()), setupProperties()); - } - - @Override - protected Predicate defineUnsupportedOperatingSystems() { - return new Predicate() { - - @Override - public boolean apply(OsFamilyVersion64Bit input) { - // TODO it seems there are no base vApp Templates available in Savvis - return true; - } - }; - } - - @Test - public void testDefaultTemplateBuilder() throws IOException { - Template defaultTemplate = context.getComputeService().templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.5"); - assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); - assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); - } - - @Override - protected Set getIso3166Codes() { - return ImmutableSet. of("US-FL", "NL-NH"); - } -} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java new file mode 100644 index 0000000000..dd573a2364 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCAsyncClientTest.java @@ -0,0 +1,99 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.features; + +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Properties; +import java.util.Set; + +import javax.inject.Named; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.RequiresHttp; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.RestContextSpec; +import org.jclouds.savvis.vpdc.VPDCAsyncClient; +import org.jclouds.savvis.vpdc.VPDCClient; +import org.jclouds.savvis.vpdc.config.VPDCRestClientModule; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.internal.VCloudSession; +import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie; +import org.jclouds.savvis.vpdc.internal.LoginAsyncClient; +import org.jclouds.savvis.vpdc.reference.VCloudMediaType; + +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * @author Adrian Cole + */ +public abstract class BaseVPDCAsyncClientTest extends RestClientTest { + + @Override + public RestContextSpec createContextSpec() { + Properties props = new Properties(); + return new RestContextFactory().createContextSpec("savvis-symphonyvpdc", "apiKey", "secretKey", props); + } + + @Override + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + } + + @Override + protected Module createModule() { + return new VPDCRestClientModuleExtension(); + } + + @RequiresHttp + @ConfiguresRestClient + public static class VPDCRestClientModuleExtension extends VPDCRestClientModule { + + @Override + protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + final LoginAsyncClient login) { + return Suppliers. ofInstance(new VCloudSession() { + + @Override + public Set getOrgs() { + return ImmutableSet.of(new Resource("1", "org", VCloudMediaType.ORG_XML, URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1"))); + } + + @Override + public String getVCloudToken() { + return "token"; + } + + }); + + } + + } + +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java new file mode 100644 index 0000000000..1f3aec75ec --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BaseVPDCClientLiveTest.java @@ -0,0 +1,85 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.features; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Properties; + +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.savvis.vpdc.VPDCAsyncClient; +import org.jclouds.savvis.vpdc.VPDCClient; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Tests behavior of {@code VPDCClient} + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseVPDCClientLiveTest { + + protected RestContext context; + protected String provider = "savvis-symphonyvpdc"; + protected String identity; + protected String credential; + protected String endpoint; + protected String apiversion; + + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); + credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider + + ".credential"); + endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); + apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider + + ".apiversion"); + } + + protected Properties setupProperties() { + Properties overrides = new Properties(); + overrides.setProperty(provider + ".identity", identity); + overrides.setProperty(provider + ".credential", credential); + overrides.setProperty(provider + ".endpoint", endpoint); + overrides.setProperty(provider + ".apiversion", apiversion); + return overrides; + } + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + setupCredentials(); + Properties overrides = setupProperties(); + context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), + overrides); + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (context != null) + context.close(); + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java new file mode 100644 index 0000000000..3c509c1ee4 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingAsyncClientTest.java @@ -0,0 +1,195 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.features; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.savvis.vpdc.xml.NetworkHandler; +import org.jclouds.savvis.vpdc.xml.OrgHandler; +import org.jclouds.savvis.vpdc.xml.TaskHandler; +import org.jclouds.savvis.vpdc.xml.VAppHandler; +import org.jclouds.savvis.vpdc.xml.VDCHandler; +import org.testng.annotations.Test; + +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code BrowsingAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest { + + public void testOrg() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getOrg", String.class); + HttpRequest request = processor.createRequest(method, "11"); + + assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testOrgNull() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getOrg", String.class); + HttpRequest request = processor.createRequest(method, (String) null); + + assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class); + HttpRequest request = processor.createRequest(method, "11", "22"); + + assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testVDCWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class); + HttpRequest request = processor.createRequest(method, (String) null, "22"); + + assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1/vdc/22 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getNetworkInOrgAndVDC", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01"); + + assertRequestLineEquals(request, + "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/network/VM-Tier01 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, NetworkHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testNetworkWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getNetworkInOrgAndVDC", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01"); + + assertRequestLineEquals(request, + "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1/vdc/22/network/VM-Tier01 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, NetworkHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testVApp() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getVAppInOrgAndVDC", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01"); + + assertRequestLineEquals(request, + "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/VM-Tier01 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testVAppWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getVAppInOrgAndVDC", String.class, String.class, + String.class); + HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01"); + + assertRequestLineEquals(request, + "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1/vdc/22/vApp/VM-Tier01 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { + Method method = BrowsingAsyncClient.class.getMethod("getTask", String.class); + HttpRequest request = processor.createRequest(method, "1"); + + assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java new file mode 100644 index 0000000000..fb528059d9 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/features/BrowsingClientLiveTest.java @@ -0,0 +1,132 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.domain.Org; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.VApp; +import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.reference.VCloudMediaType; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +@Test(groups = "live") +public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest { + + private BrowsingClient client; + + @Override + @BeforeGroups(groups = { "live" }) + public void setupClient() { + super.setupClient(); + client = context.getApi().getBrowsingClient(); + } + + @Test + public void testOrg() throws Exception { + Org response = client.getOrg(null); + assertNotNull(response); + assertNotNull(response.getId()); + assertNotNull(response.getHref()); + assertNotNull(response.getName()); + // savvis leaves this null for some reason + assertEquals(response.getType(), null); + assert response.getImages().size() >= 0; + assert response.getDescription() != null; + assert response.getVDCs().size() >= 1; + assertEquals(client.getOrg(response.getId()).toString(), response.toString()); + } + + @Test + public void testVDC() throws Exception { + Org org = client.getOrg(null); + for (Resource vdc : org.getVDCs()) { + VDC response = client.getVDCInOrg(null, vdc.getId()); + assertNotNull(response); + assertNotNull(response.getId()); + assertNotNull(response.getHref()); + assertNotNull(response.getName()); + assertNotNull(response.getStatus()); + assertEquals(response.getType(), "application/vnd.vmware.vcloud.vdc+xml"); + assertNotNull(response.getDescription()); + assertNotNull(response.getResourceEntities()); + assertNotNull(response.getAvailableNetworks()); + assertEquals(client.getVDCInOrg(null, response.getId()).toString(), response.toString()); + } + } + + @Test + public void testNetwork() throws Exception { + Org org = client.getOrg(null); + for (Resource vdc : org.getVDCs()) { + VDC VDC = client.getVDCInOrg(null, vdc.getId()); + for (Resource vApp : VDC.getAvailableNetworks()) { + Network response = client.getNetworkInOrgAndVDC(org.getId(), vdc.getId(), vApp.getId()); + assertNotNull(response); + assertNotNull(response.getId()); + assertNotNull(response.getHref()); + assertNotNull(response.getName()); + assertEquals(response.getType(), VCloudMediaType.NETWORK_XML); + assertNotNull(response.getNetmask()); + assertNotNull(response.getGateway()); + assertNotNull(response.getInternalToExternalNATRules()); + assertEquals(client.getNetworkInOrgAndVDC(null, vdc.getId(), response.getId()).toString(), + response.toString()); + } + } + } + + @Test + public void testVApp() throws Exception { + Org org = client.getOrg(null); + for (Resource vdc : org.getVDCs()) { + VDC VDC = client.getVDCInOrg(null, vdc.getId()); + for (Resource vApp : Iterables.filter(VDC.getResourceEntities(), new Predicate() { + + @Override + public boolean apply(Resource arg0) { + return VCloudMediaType.VAPP_XML.equals(arg0.getType()); + } + + })) { + VApp response = client.getVAppInOrgAndVDC(org.getId(), vdc.getId(), vApp.getId()); + assertNotNull(response); + assertNotNull(response.getId()); + assertNotNull(response.getHref()); + assertNotNull(response.getName()); + assertEquals(response.getType(), "application/vnd.vmware.vcloud.vApp+xml"); + assertNotNull(response.getIpAddress()); + assertNotNull(response.getStatus()); + assertNotNull(response.getOsDescripton()); + assertNotNull(response.getOsType()); + assertNotNull(response.getNetworkSection()); + assertNotNull(response.getResourceAllocations()); + assertEquals(client.getVAppInOrgAndVDC(null, vdc.getId(), response.getId()).toString(), response.toString()); + } + } + } +} \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java new file mode 100644 index 0000000000..87fd996497 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/filters/SetVCloudTokenCookieTest.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.filters; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import javax.inject.Provider; +import javax.ws.rs.core.HttpHeaders; + +import org.jclouds.http.HttpRequest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test +public class SetVCloudTokenCookieTest { + + private SetVCloudTokenCookie filter; + + @BeforeTest + void setUp() { + filter = new SetVCloudTokenCookie(new Provider() { + public String get() { + return "token"; + } + }); + } + + @Test + public void testApply() { + HttpRequest request = new HttpRequest("GET", URI.create("http://localhost")); + request = filter.filter(request); + assertEquals(request.getHeaders().size(), 1); + assertEquals(request.getFirstHeaderOrNull(HttpHeaders.COOKIE), "vcloud-token=token"); + + } + +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/SymphonyVPDCErrorHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandlerTest.java similarity index 96% rename from sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/SymphonyVPDCErrorHandlerTest.java rename to sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandlerTest.java index 7faefe658a..d31bf744cc 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/SymphonyVPDCErrorHandlerTest.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/handlers/VPDCErrorHandlerTest.java @@ -44,7 +44,7 @@ import com.google.inject.Guice; * @author Adrian Cole */ @Test(groups = { "unit" }) -public class SymphonyVPDCErrorHandlerTest { +public class VPDCErrorHandlerTest { @Test public void test400MakesIllegalArgumentException() { @@ -83,7 +83,7 @@ public class SymphonyVPDCErrorHandlerTest { private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, String content, Class expected) { - SymphonyVPDCErrorHandler function = Guice.createInjector().getInstance(SymphonyVPDCErrorHandler.class); + VPDCErrorHandler function = Guice.createInjector().getInstance(VPDCErrorHandler.class); HttpCommand command = createMock(HttpCommand.class); HttpRequest request = new HttpRequest(method, uri); diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java new file mode 100644 index 0000000000..5116882e20 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/NetworkHandlerTest.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.savvis.vpdc.domain.Network; +import org.jclouds.savvis.vpdc.reference.VCloudMediaType; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code NetworkHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class NetworkHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/network.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + Network result = factory.create(injector.getInstance(NetworkHandler.class)).parse(is); + assertEquals( + result.toString(), + Network.builder().type(VCloudMediaType.NETWORK_XML).name("VM-Tier01").gateway("1.1.1.1") + .netmask("255.255.255.240").build().toString()); + } + + public void testNat() { + InputStream is = getClass().getResourceAsStream("/network-nat.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + Network result = factory.create(injector.getInstance(NetworkHandler.class)).parse(is); + assertEquals(result.toString(), + Network.builder().type(VCloudMediaType.NETWORK_XML).name("VM Tier01").gateway("1.1.1.1").netmask("2.2.2.2") + .internalToExternalNATRule("3.3.3.3", "4.4.4.4").internalToExternalNATRule("3.3.3.4", "4.4.4.5") + .build().toString()); + } + + public void tesWhenNoVAppsInNetworkSetsAllZerosToGatewayAndNetmask() { + InputStream is = getClass().getResourceAsStream("/network-unused.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + Network result = factory.create(injector.getInstance(NetworkHandler.class)).parse(is); + assertEquals(result.toString(), + Network.builder().type(VCloudMediaType.NETWORK_XML).name("VM Tier01").gateway("0.0.0.0").netmask("0.0.0.0") + .build().toString()); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java index 3725b4cacb..fb55ebf01c 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgHandlerTest.java @@ -27,16 +27,10 @@ import java.net.URI; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.vcloud.domain.Org; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.internal.OrgImpl; -import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; -import org.jclouds.vcloud.xml.OrgHandler; +import org.jclouds.savvis.vpdc.domain.Link; +import org.jclouds.savvis.vpdc.domain.Org; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.google.inject.Guice; import com.google.inject.Injector; @@ -49,18 +43,18 @@ import com.google.inject.Injector; public class OrgHandlerTest { public void testSavvis() { - InputStream is = getClass().getResourceAsStream("/savvis/org.xml"); + InputStream is = getClass().getResourceAsStream("/org.xml"); Injector injector = Guice.createInjector(new SaxParserModule()); Factory factory = injector.getInstance(ParseSax.Factory.class); - Org result = (Org) factory.create(injector.getInstance(OrgHandler.class)).parse(is); + Org result = factory.create(injector.getInstance(OrgHandler.class)).parse(is); assertEquals( - result, - new OrgImpl("100000.0", null, null, "100000.0", "SAVVISStation Integration Testing", ImmutableMap - . of(), ImmutableMap. of( - "demo_vpdcname", - new ReferenceTypeImpl("demo_vpdcname", "application/vnd.vmware.vcloud.vdc+xml", URI - .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736"))), - ImmutableMap. of(), null, ImmutableSet. of())); + result.toString(), + Org.builder() + .name("100000.0") + .description("SAVVISStation Integration Testing") + .vDC(new Link("2736", "demo_vpdcname", "application/vnd.vmware.vcloud.vdc+xml", URI + .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736"), + "down")).build().toString()); } } diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java new file mode 100644 index 0000000000..d21725134f --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/OrgListHandlerTest.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.Set; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code OrgListHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class OrgListHandlerTest { + + public void testSavvis() { + InputStream is = getClass().getResourceAsStream("/orglist.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + Set result = factory.create(injector.getInstance(OrgListHandler.class)).parse(is); + assertEquals(result, ImmutableSet.of(new Resource("100000.0", "SAVVISStation Integration Testing", + "application/vnd.vmware.vcloud.org+xml", URI + .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0")))); + + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandlerTest.java new file mode 100644 index 0000000000..8c3a79b483 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/ResourceAllocationHandlerTest.java @@ -0,0 +1,32 @@ +package org.jclouds.savvis.vpdc.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.savvis.vpdc.domain.ResourceAllocation; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code ResourceAllocationHandler} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "ResourceAllocationHandlerTest") +public class ResourceAllocationHandlerTest extends BaseHandlerTest { + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/resourceallocation.xml"); + + ResourceAllocation result = factory.create(injector.getInstance(ResourceAllocationHandler.class)).parse(is); + + ResourceAllocation expects = ResourceAllocation.builder() + + .allocationUnits("Gigabytes").caption("1234568").description("Hard Disk").name("D:\\").hostResource("data").id(6) + .type(ResourceAllocation.Type.DATA_DISK).virtualQuantity(50) + .build(); + assertEquals(result, expects); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandlerTest.java deleted file mode 100644 index 9a19945b85..0000000000 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/SymphonyVPDCVDCHandlerTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * 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.jclouds.savvis.vpdc.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.net.URI; - -import org.jclouds.http.functions.ParseSax; -import org.jclouds.http.functions.ParseSax.Factory; -import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.savvis.vpdc.domain.SymphonyVPDCVDC; -import org.jclouds.vcloud.VCloudMediaType; -import org.jclouds.vcloud.domain.ReferenceType; -import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code SymphonyVPDCVDCHandler} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class SymphonyVPDCVDCHandlerTest { - - public void test() { - InputStream is = getClass().getResourceAsStream("/savvis/vdc.xml"); - Injector injector = Guice.createInjector(new SaxParserModule()); - Factory factory = injector.getInstance(ParseSax.Factory.class); - SymphonyVPDCVDC result = (SymphonyVPDCVDC) factory.create(injector.getInstance(SymphonyVPDCVDCHandler.class)) - .parse(is); - assertEquals(result.getName(), "demo_vpdcname"); - assertEquals(result.getHref(), null); - assertEquals(result.getDescription(), - "ServiceProfileName = Balanced; ServiceLocation = North America; Email = jim@company.com;"); - assertEquals(result.getOfferingTag(), "Deployed"); - assertEquals(result.getStorageCapacity(), null); - assertEquals(result.getCpuCapacity(), null); - assertEquals(result.getMemoryCapacity(), null); - assertEquals(result.getVmQuota(), 0); - assertEquals( - result.getResourceEntities(), - ImmutableMap. of( - "DemoHost-1", - new ReferenceTypeImpl( - "DemoHost-1", - VCloudMediaType.VAPP_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")), - "DemoHost-2", - new ReferenceTypeImpl( - "DemoHost-2", - VCloudMediaType.VAPP_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")), - "DemoHost-3", - new ReferenceTypeImpl( - "DemoHost-3", - VCloudMediaType.VAPP_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1003")), - "CustomerTemplateName", - new ReferenceTypeImpl( - "CustomerTemplateName", - VCloudMediaType.VAPPTEMPLATE_XML, - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vAppTemplate/1234")), - "firewall", - new ReferenceTypeImpl( - "firewall", - "api.sandbox.symphonyVPDC.savvis.net+xml", - URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/FirewallService")))); - assertEquals(result.getAvailableNetworks(), ImmutableMap.of()); - } -} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java new file mode 100644 index 0000000000..547d6e7b97 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/TaskHandlerTest.java @@ -0,0 +1,248 @@ +package org.jclouds.savvis.vpdc.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.date.DateService; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.Task; +import org.jclouds.savvis.vpdc.domain.TaskError; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code TaskHandler} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "TaskHandlerTest") +public class TaskHandlerTest extends BaseHandlerTest { + + private DateService dateService; + + @BeforeTest + @Override + protected void setUpInjector() { + super.setUpInjector(); + dateService = injector.getInstance(DateService.class); + } + + public void testVAppSuccess() { + InputStream is = getClass().getResourceAsStream("/task-vapp.xml"); + + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + Task expects = Task + .builder() + .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) + .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) + .status(Task.Status.SUCCESS) + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/21-1002")) + .owner( + Resource + .builder() + .id("2736") + .name("mockVpdc8") + .type("application/vnd.vmware.vcloud.vdc+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) + .build()) + .result( + Resource + .builder() + .id("1002") + .name("mock_vpdc_item_007") + .type("application/vnd.vmware.vcloud.vApp+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")) + .build()).build(); + assertEquals(result.toString(), expects.toString()); + + } + + public void testVMDKSuccess() { + InputStream is = getClass().getResourceAsStream("/task-vmdk.xml"); + + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + Task expects = Task + .builder() + .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) + .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) + .status(Task.Status.SUCCESS) + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/21-1002")) + .owner( + Resource + .builder() + .id("2736") + .name("mockVpdc8") + .type("application/vnd.vmware.vcloud.vdc+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) + .build()) + .result( + Resource + .builder() + .id("1234567") + .name("mock_vpdc_item_008") + .type("application/vnd.vmware.vcloud.vApp+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/vdc/2736/vmdk/1234567")) + .build()).build(); + assertEquals(result.toString(), expects.toString()); + + } + + public void testRunning() { + InputStream is = getClass().getResourceAsStream("/task-running.xml"); + + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + Task expects = Task + .builder() + .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) + .status(Task.Status.RUNNING) + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/21-1002")) + .owner( + Resource + .builder() + .id("2736") + .name("mockVpdc8") + .type("application/vnd.vmware.vcloud.vdc+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) + .build()) + .result( + Resource + .builder() + .id("1002") + .name("mock_vpdc_item_007") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")) + .build()).build(); + + assertEquals(result.toString(), expects.toString()); + + } + + public void testQueued() { + InputStream is = getClass().getResourceAsStream("/task-queued.xml"); + + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + Task expects = Task + .builder() + .id("6904") + .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) + .status(Task.Status.QUEUED) + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904")) + .owner( + Resource + .builder() + .id("2736") + .name("mockVpdc8") + .type("application/vnd.vmware.vcloud.vdc+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) + .build()) + .result( + Resource + .builder() + .id("1002") + .name("mock_vpdc_item_007") + .type("application/vnd.vmware.vcloud.catalogItem+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")) + .build()).build(); + assertEquals(result.toString(), expects.toString()); + + } + + public void testFailed() { + InputStream is = getClass().getResourceAsStream("/task-failed.xml"); + + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + Task expects = Task + .builder() + .id("6904-123") + .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) + .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) + .status(Task.Status.ERROR) + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123")) + .owner( + Resource + .builder() + .id("2736") + .name("mockVpdc8") + .type("application/vnd.vmware.vcloud.vdc+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736")) + .build()) + .result( + Resource + .builder() + .id("1002") + .name("mock_vpdc_item_007") + .type("application/vnd.vmware.vcloud.vApp+xml") + .href(URI + .create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")) + .build()).build(); + assertEquals(result.toString(), expects.toString()); + + } + + public void testError() { + InputStream is = getClass().getResourceAsStream("/task-error.xml"); + + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + Task expects = Task + .builder() + .id("6904-123") + .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) + .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) + .status(Task.Status.ERROR) + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123")) + .error( + TaskError + .builder() + .vendorSpecificErrorCode("0") + .minorErrorCode(0) + .majorErrorCode(0) + .message( + "There is an internal exception occured in System, please kindly contact savvis support team to get solution.") + .build()).build(); + assertEquals(result.toString(), expects.toString()); + + } + + public void testUnsupported() { + InputStream is = getClass().getResourceAsStream("/task-unsupported.xml"); + + Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); + Task expects = Task + .builder() + .id("6904-123") + .startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00")) + .endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00")) + .status(Task.Status.NONE) + .type("application/vnd.vmware.vcloud.task+xml") + .href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123")) + .error( + TaskError + .builder() + .vendorSpecificErrorCode("3000") + .minorErrorCode(-1) + .majorErrorCode(500) + .message( + "your requested task id is not found. Please contact Savvis Administrator for further assistance/clarification ") + .build()).build(); + assertEquals(result.toString(), expects.toString()); + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java new file mode 100644 index 0000000000..2bce26a353 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java @@ -0,0 +1,194 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.savvis.vpdc.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.SaxParserModule; +import org.jclouds.savvis.vpdc.domain.Resource; +import org.jclouds.savvis.vpdc.domain.VDC; +import org.jclouds.savvis.vpdc.domain.VDC.Status; +import org.jclouds.savvis.vpdc.reference.VCloudMediaType; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code VDCHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class VDCHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/vdc.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "demo_vpdcname"); + assertEquals(result.getDescription(), + "ServiceProfileName = Balanced; ServiceLocation = North America; Email = jim@company.com;"); + assertEquals(result.getStatus(), Status.DEPLOYED); + assertEquals( + result.getResourceEntities(), + ImmutableSet. of( + new Resource( + "1001", + "DemoHost-1", + VCloudMediaType.VAPP_XML, + URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")), + new Resource( + "1002", + "DemoHost-2", + VCloudMediaType.VAPP_XML, + URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")), + new Resource( + "1003", + "DemoHost-3", + VCloudMediaType.VAPP_XML, + URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1003")), + new Resource( + "1234", + "CustomerTemplateName", + VCloudMediaType.VAPPTEMPLATE_XML, + URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vAppTemplate/1234")), + new Resource( + "FirewallService", + "firewall", + "api.symphonyvpdc.savvis.net+xml", + URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/FirewallService")))); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of()); + } + + public void test1net() { + InputStream is = getClass().getResourceAsStream("/vdc-1net.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "demo6"); + assertEquals(result.getDescription(), + "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;"); + assertEquals(result.getStatus(), Status.DEPLOYED); + assertEquals(result.getResourceEntities(), ImmutableSet.of( + new Resource("1001", "Host1", VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1001")), + new Resource("1002", "Host2", VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1002")), + new Resource("1003", "Host3", VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1003")), + new Resource("1004", "Host4", VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1004")))); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of(Resource + .builder() + .id("VM-Tier01") + .name("VM Tier01") + .type(VCloudMediaType.NETWORK_XML) + .href(URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/network/VM-Tier01")) + .build())); + + } + + public void testFailed() { + InputStream is = getClass().getResourceAsStream("/vdc-failed.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "Demo7"); + assertEquals(result.getDescription(), + "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;"); + assertEquals(result.getStatus(), Status.FAILED); + assertEquals(result.getResourceEntities(), ImmutableSet.of(new Resource("1001", "Host1", + VCloudMediaType.VAPP_XML, URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/vApp/1001")))); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of(Resource + .builder() + .id("VM-Tier01") + .name("VM Tier01") + .type(VCloudMediaType.NETWORK_XML) + .href(URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/network/VM-Tier01")) + .build())); + + } + + public void testSaved() { + InputStream is = getClass().getResourceAsStream("/vdc-saved.xml"); + Injector injector = Guice.createInjector(new SaxParserModule()); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "CloudBurst1"); + assertEquals(result.getDescription(), + "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = me@my.com;"); + assertEquals(result.getStatus(), Status.SAVED); + assertEquals( + result.getResourceEntities(), + ImmutableSet.of( + Resource + .builder() + .name("templateHost") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1001") + .href(URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1001")) + .build(), + Resource + .builder() + .name("host-c501") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1037") + .href(URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1037")) + .build(), + Resource + .builder() + .name("host-c501") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1038") + .href(URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1038")) + .build(), + Resource + .builder() + .name("host-c601") + .type("application/vnd.vmware.vcloud.vApp+xml") + .id("1039") + .href(URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1039")) + .build())); + assertEquals(result.getAvailableNetworks(), ImmutableSet.of(Resource + .builder() + .id("VM-Tier01") + .name("VM Tier01") + .type(VCloudMediaType.NETWORK_XML) + .href(URI + .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/network/VM-Tier01")) + .build())); + + } +} diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/log4j.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/log4j.xml new file mode 100644 index 0000000000..7343ec00e2 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/log4j.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-nat.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-nat.xml new file mode 100644 index 0000000000..0de09a6782 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-nat.xml @@ -0,0 +1,18 @@ + + + + 1.1.1.1 + 2.2.2.2 + + + allowInOut + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-unused.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-unused.xml new file mode 100644 index 0000000000..5cade31b8b --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network-unused.xml @@ -0,0 +1,14 @@ + + + + 0.0.0.0 + 0.0.0.0 + + + allowInOut + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network.xml new file mode 100644 index 0000000000..43b568b1e7 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/network.xml @@ -0,0 +1,10 @@ + + + + 1.1.1.1 + 255.255.255.240 + + + allowInOut + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/savvis/org.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/org.xml similarity index 100% rename from sandbox-providers/savvis-symphony-vpdc/src/test/resources/savvis/org.xml rename to sandbox-providers/savvis-symphony-vpdc/src/test/resources/org.xml diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/orglist.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/orglist.xml new file mode 100644 index 0000000000..24367a5bdc --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/orglist.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/resourceallocation.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/resourceallocation.xml new file mode 100644 index 0000000000..e8cede2d99 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/resourceallocation.xml @@ -0,0 +1,26 @@ + + + + Gigabytes + + + 1234568 + + + + Hard Disk + D:\ + + data + 6 + + + + + + + + 26 + 50 + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-error.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-error.xml new file mode 100644 index 0000000000..32ef2b6c69 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-error.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-failed.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-failed.xml new file mode 100644 index 0000000000..d14ef3f814 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-failed.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-queued.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-queued.xml new file mode 100644 index 0000000000..1412912cd0 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-queued.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-running.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-running.xml new file mode 100644 index 0000000000..1b42f0052f --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-running.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-unsupported.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-unsupported.xml new file mode 100644 index 0000000000..60a56580c6 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-unsupported.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vapp.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vapp.xml new file mode 100644 index 0000000000..8a8a3520c1 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vapp.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vmdk.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vmdk.xml new file mode 100644 index 0000000000..f3368dec3c --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/task-vmdk.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-1net.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-1net.xml new file mode 100644 index 0000000000..52a387acd4 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-1net.xml @@ -0,0 +1,14 @@ + + + ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com; + Deployed + + + + + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-failed.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-failed.xml new file mode 100644 index 0000000000..16a8e932b5 --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-failed.xml @@ -0,0 +1,11 @@ + + + ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com; + Failed + + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-saved.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-saved.xml new file mode 100644 index 0000000000..3dccdf3dfb --- /dev/null +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc-saved.xml @@ -0,0 +1,14 @@ + + + ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = me@my.com; + Saved + + + + + + + + + + \ No newline at end of file diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/savvis/vdc.xml b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc.xml similarity index 88% rename from sandbox-providers/savvis-symphony-vpdc/src/test/resources/savvis/vdc.xml rename to sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc.xml index 57d28ef190..d52b555094 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/resources/savvis/vdc.xml +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/resources/vdc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file